views:

321

answers:

3

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.

A: 

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.

Scott Langham
A: 

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.

Scott Langham
+2  A: 

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.

Shane Powell