Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now