Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

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…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Suggested Courses

734 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