Solved

Unlock a file so it can be deleted, VB.NET (Compact Framework v2)

Posted on 2011-03-08
3
987 Views
Last Modified: 2013-12-27
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!

0
Comment
Question by:MrFawlty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 16

Expert Comment

by:hjgode
ID: 35071256
Hello

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.

0
 
LVL 16

Accepted Solution

by:
Kalpesh Chhatrala earned 500 total points
ID: 35071268
you can lock file using following comand. there after you can delete it.

using (FileStream fs = 
           File.Open("MyFile.txt", FileMode.Open, FileAccess.Read, FileShare.None))
{
   // use fs
}

Open in new window

0
 

Author Comment

by:MrFawlty
ID: 35154390
Hi,

Will this release a file being used by another process so it can be deleted?

Kind regards,

MrFawlty
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are anything like me, you install many apps on your phone and have your life on it, sometimes literally.  When I bought my current phone, a Samsung Galaxy S5 from Verizon, they were only selling the versions with 16 GB internal.  I didn't rea…
I recently asked a question (http://www.experts-exchange.com/Programming/Smartphones/Android/Q_28684946.html) about Computer Inventory applications for Mobile Devices.  I was specifically interested in an app I could use on my android phone.  The be…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question