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
Solved

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

Posted on 2011-03-08
3
941 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
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

With Windows Embedded Handheld, called Windows Mobile, Microsoft re-designed the user interface. The Start Icon moved down to the bottom, inside the menu bar area.   If you need to hide the Start Icon and/or the SIP (soft input panel, softwar…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

856 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