chrisfixit
asked on
How can I delete a 'locked' file in VB NET?
I have a windows service that I wrote in VB NET which periodically copies and replaces a file in another applications directory.
This has been working fine, but the latest version of the app now has the file I wish to overwrite 'locked' so my service fails when I try and delete the file.
How can I get around this - it won't cause a crash cos the program I'm overwriting only shows a splash screen which I overwrite with my own depending on the time of day.
This has been working fine, but the latest version of the app now has the file I wish to overwrite 'locked' so my service fails when I try and delete the file.
How can I get around this - it won't cause a crash cos the program I'm overwriting only shows a splash screen which I overwrite with my own depending on the time of day.
ASKER
advanced and dangerous is good.
At the moment I simply..
If System.IO.File.Exists(NewC opy) = True Then
System.IO.File.Delete(NewC opy)
End If
If System.IO.File.Exists(File ToCopy) = True Then
System.IO.File.Copy(FileTo Copy, NewCopy)
End If
At the moment I simply..
If System.IO.File.Exists(NewC
System.IO.File.Delete(NewC
End If
If System.IO.File.Exists(File
System.IO.File.Copy(FileTo
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It seems it is a different problem..for some reason on that particular system the whole directory is write protected - i can't see what is doing it .
Anyway thanks.
Anyway thanks.
Even if it is closed, I would like to propose using sysinternals process explorer and process monitor to nail these things. In Process Monitor you can search for handles by name of the file they point to. So in this case you can look for your directory in that search and see who holds it.
Also with procmon running you can watch your own process to see exactly what windows calls are being made and what the system results are to better understand the problem.
http://live.sysinternals.com/
Also with procmon running you can watch your own process to see exactly what windows calls are being made and what the system results are to better understand the problem.
http://live.sysinternals.com/
Normally a locked file is locked, that's the whole idea and you can't get around it without shutting down the application that holds the lock (well there are ways but they are advanced and danagerous).