The installation directory issue cannot be removed when you uninstall Visual Studio Installer

Source: Internet
Author: User
Tags visual studio installer

?

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.