How to uninstall programmatically yourself? (C # WinMobile)

How can I programmatically delete it myself?

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

Please, I do not want to discuss WHY to do this, I just need to know HOW to do it!

Important:

  • The “second application” approach is NOT an option. (If this second application cannot be "extracted" from the running application, but I do not know how to do it!).

  • There is no problem with a forced reboot if the windows do the trick at startup. (Is this possible? Pleasant! Show me how!).

  • Code examples are welcome.

+6
c # windows-mobile
source share
4 answers

The only way I can think about removing myself and leaving no traces is to use something already present in the device, namely wceload (CAB extractor). I would create a simple CAB file with a custom installation of the DLL, which will wait and then delete.

Then I will add the CAB to the application as an embedded resource. When you need to remove you

  • extract the cab to the file system
  • execute wceload.exe with CAB as a parameter and / noui (or / silent)
  • Close the application

Then CAB deletes your file (named mutex can synchronize this better than just calling sleep in a DLL). wceload automatically removes the CAB (well, depending on the version of WinMo, but there is a switch to force removal if necessary).

This, of course, is a hack, but it will provide a "leave without a trace" removal. Of course, CAB may have to clean its own registry entries for installation. Perhaps you can simply set the installation to “failure” so that they are not recorded first.

+5
source share

I have done this in the past by simply writing a batch file on a file system that will wait a few seconds and then delete the program. Then you use Process.Start() to run the batch file and immediately call Environment.Exit() . You must make sure that the batch file waits long enough for your program to close, or it will not work.

+1
source share

I use this code and it works great

 string AppPath = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location).ToString() + "\\Uninstaller.exe"; ProcessStartInfo Info = new ProcessStartInfo(); Info.Arguments = "/C choice /CY /N /DY /T 0 & Del " + AppPath; Info.WindowStyle = ProcessWindowStyle.Hidden; Info.CreateNoWindow = true; Info.FileName = "cmd.exe"; Process.Start(Info); 
+1
source share

Windows may delete files at startup. This can be done by calling MoveFileEx , for example:

 MoveFileEx(szDstFile, NULL, MOVEFILE_DELAY_UNTIL_REBOOT); 

I'm not sure if this API is available in Mobile 6 or not. However, what it actually does is create a registry entry in HKEY_LOCAL_MACHINE \ System \ CurrentControlSet \ Control \ Session Manager \ PendingFileRenameOperations. The key is REG_MULI_SZ, and you just need to give it a value like "szDstFile \ 0 \ 0". When you restart, Windows deletes the file.

Regarding software reboot, check out this thread on SO.

-one
source share

All Articles