What's the best way for a .NET Compact Framework executable to delete itself?

I'd like my .NET Compact Framework app to delete itself after it finishes executing. What's the best way to do this?

On a Windows machine it's possible to do this using a .bat file, but that's not an option on mobile devices.

Answers


In Windows Mobile there is the directory:

\application data\volatile

This directory is kept for as long as the device has power.

So what we do is:

  1. copy a exe over to this directory, or a sub-directory (I normally use a sub-directory to make sure we don't clash with another application).
  2. run the exe from this directory.
  3. delete the files you want.
  4. (optional) soft-reset.

For compatiblity with all devices you should use the "SHGetSpecialFolderPath" function with CSIDL_APPDATA to get the application data directory and append "\volatile" to it.


One idea is you could use wceload:

http://msdn.microsoft.com/en-us/library/bb158700.aspx

Write a cab file that has a custom step (I think you might need to create a setup.dll) that will delete your application.

Get your application to call wceload when it exits to run this cab, passing the argument for wce load to delete the cab after it's finished running.

Not very slick I know.


Write your own deleter.exe program and run that to delete your main exe, but you'd have to leave that behind on the device... unless your device has a ram drive you could run deleter.exe from, so that it would disappear on reboot.


Need Your Help

Grid View inside Grid view

asp.net view grid

I have a master grid and a child grid which is one of the column of the master Grid and whose data is getting bound to datasource on rowDataBound of master grid view. Now the thing that I want is t...

What do you do if the file in TFS is locked by someone else?

version-control command-line tfs administration

Someone left the organisation but before leaving, he locked all the files for an unknown reason.