I recently had a problem where I was starting a process in another folder to update the calling program and the folder was locked. Here is what I was trying to do:
- Main program extracts update files to temp directory.
- Main program starts update program and closes.
- Update program deletes main program directory.
- Update program extracts updated main program directory.
- Update program starts updated main program and closes.
My problem was that when trying to delete the main program directory the folder was locked. Using Unlocker, it showed my update program having the lock. If I started the update program manually the lock wasn’t there. So I figured the lock was some side effect of me starting the update program from the main program.
Here is how I was starting the update program:
Dim p As New ProcessStartInfo p.FileName = Other.UserTempPath & "\IBSi Updater\IBSi Updater.exe" p.Arguments = """" & Application.StartupPath & """" Process.Start(p)
And here is the simple solution on how to fix it:
Dim p As New ProcessStartInfo p.FileName = Other.UserTempPath & "\IBSi Updater\IBSi Updater.exe" p.Arguments = """" & Application.StartupPath & """" p.WorkingDirectory = Other.UserTempPath & "\IBSi Updater" Process.Start(p)
By making sure to set the WorkingDirectory, we tell the thread where it is and it locks it automatically so you don’t delete the executable that is running the thread. By not setting it, it takes the location of the thread that called it which in this case was not what I wanted.






No comments yet.
Leave a comment