Click here to Skip to main content
15,883,796 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
A few days back I faced this problem at work and I was wondering is there a way to mint out more data from the scenario than to go to Microsoft. There has been many cases like this and I wanted to explore that as a windows developer what is the best /optimum way to fetch most of info is such case. I ll describe the situation:

1) An office application, while printing with certain settings ,involving cmyk color space, throws up a dialog box error which has a bad description."File %s could not be opened because it is locked by some other application". It does not give a file name nor does the event viewer. Printing is aborted.

2) on using "procmon", we find "file locked error" on several files when the api "CreatefileMapping" is called by involved processes like the office app, the spooler , the splwow64.exe(yes its a 64 bit system and the app is 32 bit).

3) the problem is not there when there is no splwow64 is involved, means using 64 bit app on 64 bit os.

I want to know that which tools will be useful for getting more info in such situations. This includes use of MS symbols with windbg and debugging assembly if needed. Basically i need the file name that is locked , which is shown as %s and the root of the problem.
Posted
Updated 30-May-14 9:33am
v2

1 solution

Such debugging is possible but not really productive, too much labor-taking. And having debugging without the ability to patch the PE (I used to work with the system providing patch facility, but that's far from Windows :-)) won't help you much.

But you mentioned the "because it is locked by some other application", which is pretty easy to detect and fix.

First of all, the similar question was asked here many times, and from this experience I know: in most cases the blocking process is your own process. You could have forgotten to dispose/close something in the same application. So, first of all, check it up. To explore this possibility, please see my past answer:
Clearing a Handle in C#[^].

In this answer, pay attention for the using of the using statement which helps you to guarantee that appropriate file system object is properly disposed after use, not keeping the file locked.

In some cases, you really need to investigate which process holds which file. For this, I recommend using one utility from the Sysinternals Suite. This set of utilities (formerly from Winternals company, presently at Microsoft) is a must-have for any developer, please see:
http://technet.microsoft.com/en-us/sysinternals/bb842062[^],
http://technet.microsoft.com/en-us/sysinternals/bb545027[^].

The utility you need is "handle.exe", please see:
http://technet.microsoft.com/en-us/sysinternals/bb896655[^].

In your case, you use it with file name parameter:
handle.exe <file_name>


This utility will scan all kinds of handles, not just file handles. For file, it will scan all file handles matching the file name (so it does not have to be a full path name) and return information sufficient to identify each process, including its pid. So, if you need more information on a process in question, you can also use other Sysinternals utilities, in particular, its Process Explorer:
http://technet.microsoft.com/en-us/sysinternals/bb896653[^].

Good luck,
—SA
 
Share this answer
 
v2
Comments
kaushik_code 30-May-14 22:18pm    
Sounds like a good approach to attack the problem.Thank you.
Sergey Alexandrovich Kryukov 31-May-14 0:55am    
Well, it immediately helped me is such cases. Good luck.
Call again.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900