05-04-2011 08:13 AM
Hi
Strict to the point.
Say you have a file which is in use by another program and you try to open it for read and write using fopen() or (WinAPI)CreateFile() and you get an error access denied.
Is there a way that you can get a shared handle on that connection ?
or is there a way to terminate the connection that the file currently has?
05-05-2011 11:57 AM
I think this generally depends on how you open in the other program. If it locks the file, there is no way to get that resource with the first program letting it go. The only way I can think of to get the other program to let it go if you cannot change the code of the other program to play nice, is to send a command to to the OS to kill the program, and it should then release the resource. The best solution would be to alter the code of the other program to accept a message to let go of the resource, or open it without locking the file such as read only.
05-06-2011 01:28 AM
Thanks for the reply.
How do i get the name of the process the has locked the file so that i could warn the user and request for it to be terminated.
I wont be able to change the code because the program locking it is not open source.
05-06-2011 03:25 PM
There is an article I found here that explains how if you are using windows XP the process is pretty similar, and I think you can figure it out in Vista or 7 with the same tutorial. If not let me know and I will find you some more resources.
05-09-2011 02:00 AM
Thanks this is what i was looking for.
One thing is, how can i get this information into CVI for me to use?
05-09-2011 04:24 AM
Where can i get the libraries so that i can do this with CVI?
05-10-2011 11:30 AM
You could pass it in from the command line or a user interface, but I have not found a way to get all of that information programmatically. That doesn't mean it is not possible. I assume there are some windows library calls, or commandline arugments you could exec and pull in the output to get the data. I have never actually tried, and have not been able to find an example or documentation however.
05-11-2011 01:03 AM
What i have done is to save the information to a txt file and use my program to decode the text file, it works but it is not the ideal solution.
If you do come across how to do this directly from the exe file please post it, I will do the same.
Thanks for your help.
05-12-2011 11:05 AM
Sounds like a plan. I will keep looking and post back if I find something useful.