LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

File Handling and Connections?

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?

 

Help share your knowlegde
0 Kudos
Message 1 of 9
(3,327 Views)

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.

Jensen
National Instruments
Applications Engineer
0 Kudos
Message 2 of 9
(3,314 Views)

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.

Help share your knowlegde
0 Kudos
Message 3 of 9
(3,303 Views)

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.

Jensen
National Instruments
Applications Engineer
0 Kudos
Message 4 of 9
(3,289 Views)

Thanks this is what i was looking for.

 

One thing is, how can i get this information into CVI for me to use?

Help share your knowlegde
0 Kudos
Message 5 of 9
(3,283 Views)

Where can i get the libraries so that i can do this with CVI?

Help share your knowlegde
0 Kudos
Message 6 of 9
(3,275 Views)

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.

Jensen
National Instruments
Applications Engineer
0 Kudos
Message 7 of 9
(3,244 Views)

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.

 

Help share your knowlegde
0 Kudos
Message 8 of 9
(3,229 Views)

Sounds like a plan.  I will keep looking and post back if I find something useful.

 

Jensen
National Instruments
Applications Engineer
0 Kudos
Message 9 of 9
(3,215 Views)