Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically self delete? (C# WinMobile)

How do I programmatically self delete?

C# / .NET Compact Framework 2 / Windows Mobile 6

Please, I don't want to discuss WHY to do it, I just need to know HOW to do it!

Important:

  • The "second application" approach is NOT an option. (Unless that second application can be "extracted" from running app, but I don't know how to do it!).

  • No problem in forced reboot, if windows do the trick at startup. (Is it possible? Nice! Show me how!).

  • Code samples are welcome.

like image 239
Christian Avatar asked Apr 08 '10 21:04

Christian


2 Answers

The only way I can think of offhand to delete yourself and leave no trace is to use something already present in the device- namely wceload (the CAB extractor). I'd create a simple CAB file with a custom installer DLL that does a wait and then the delete.

I'd then add the CAB to the app as an embedded resource. When you need to delete you

  1. extract the CAB to the file system
  2. execute wceload.exe with the CAB as a parameter and /noui (or /silent)
  3. Quit your application

The CAB then deletes your file (a named mutex could sync this better than just a Sleep call in the DLL). wceload automatically deletes the CAB (well depending on WinMo version, but there is a switch to force delete if necessary).

It's certainly a hack, but it would provide a "leave no trace" delete. Of course the CAB would probably have to clean it's own installation registry entries as well. Maybe you could just have the install return "failure" to prevent them from being written in the first place.

like image 184
ctacke Avatar answered Oct 13 '22 01:10

ctacke


I am using this code and it works fine

string AppPath = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location).ToString() + "\\Uninstaller.exe";

ProcessStartInfo Info = new ProcessStartInfo();
Info.Arguments = "/C choice /C Y /N /D Y /T 0 & Del " + AppPath;
Info.WindowStyle = ProcessWindowStyle.Hidden;
Info.CreateNoWindow = true;
Info.FileName = "cmd.exe";
Process.Start(Info);
like image 35
Sunil Agarwal Avatar answered Oct 13 '22 01:10

Sunil Agarwal