MrFawlty
asked on
Unlock a file so it can be deleted, VB.NET (Compact Framework v2)
Hi,
Sometimes files are blocked on a mobile devices that need to be deleted, can someone help me putting together a Function or Sub that enables me cut all ties to that file and permanently delete it.
Thank you for any advice!
Sometimes files are blocked on a mobile devices that need to be deleted, can someone help me putting together a Function or Sub that enables me cut all ties to that file and permanently delete it.
Thank you for any advice!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
Will this release a file being used by another process so it can be deleted?
Kind regards,
MrFawlty
Will this release a file being used by another process so it can be deleted?
Kind regards,
MrFawlty
before you can delete files that are in use of some process, you need to know which app is locking the file. Unfortunately I dont know a function to get a list of processes that lock a specific file. This is also not that simple on desktop windows (see sysinternals process explorer).
I recommend to kill all unneeded processes before you try to delete a file. If you are more specific and can tell us the names of the files we probably know the process to kill.
Build a process list using toolhelp API (CreateToolhelp32Snapshot API) and then quit or kill the processes (SendMessage WM_QUIT or TerminateProcess()).
Another approach is to delete a file during OS startup just after a reboot, so that most processes do not yet run. You can do this with an AutoRun.exe placed in 2577 dir of root of the device or a SD Card, if the device is using a XScale/Arm processor. The name 2577 of the dir depends on the processor of the device. The OS will look for AutoRun.exe during startup in that specific dir on all volumes.