?
The installation program can be made in VS, but this installer will not uninstall the installation directory by default, if you want to delete the directory when uninstalling, it will be a bit of a hassle. This method is suitable for both program self-deletion and working directory deletion.
The basic idea is to start a script when the program exits, and the script will do the work and delete all unnecessary things. Note that this script should delete the working directory after the program exits completely.
Directly affixed to the code, the idea is very simple, mainly through a ping to delay, to ensure that the program exit and then delete.
protected Override void Onafteruninstall (IDictionarysavedstate)
{
Assembly asm = Assembly. getexecutingassembly ();
string path = asm. location. Remove (ASM. location. LastIndexOf ("\\"));
deleteallself (path);
}
Static void deleteallself (stringpath)
{
System. IO. Directory. setcurrentdirectory ("c:\");
string fileName = Path. Combine ("c:\ \", "Remove.bat");
StreamWriter bat = newStreamWriter(fileName, false, Encoding. Default);
bat. WriteLine ("Ping 127.0.0.1-n 7 > nul"); // The delay here is very necessary ,, Guarantee to delete the directory when the program has been completely exited !
bat. WriteLine (string. Format ("rd \"{0}\ " /q/s", path);
bat. WriteLine (string. Format ("del \"{0}\ "/ Q", fileName);
?
bat. Close ();
ProcessStartInfo Info = newprocessstartinfo(fileName);
Info. workingdirectory = "c:\ \";
Info. windowstyle = ProcessWindowStyle. Hidden;
Process. Start (info);
}
The installation directory issue cannot be removed when you uninstall Visual Studio Installer