Automated Testing (4) Automatic Software Uninstall

Source: Internet
Author: User

In normal testing work, software is often installed and uninstalled, Which is cumbersome and tiring. Installation and uninstallation can be automated. For software installation, we can use the automation framework and click Next to install the software automatically. Uninstall software. We can use the msiexec command line tool to automatically uninstall the software.

 

Reading directory

  1. Run the msiexec command to uninstall the software.
  2. Search for ProductCode in the Registry
  3. C # automatically uninstall software
  4. C # search for ProductCode in the Registry
  5. Download complete source code

 

Run the msiexec command to uninstall the software.

We usually manually uninstall the software by going to the "Add/Delete" program in the control panel to uninstall the software, or by uninstalling the software that comes with the program.

You can run the MsiExec.exe/X {ProductCode} command to uninstall the program.

About msiexec.exe see http://technet.microsoft.com/zh-cn/library/cc759262%28v=WS.10%29.aspx

 

Search for ProductCode in the Registry

ProductCode is the Globally Unique Identifier (GUID) of the Windows installation package. You can obtain ProductCode through the registry.

 

Instance: Use msiexec.exe to automatically uninstall Xmarks.

Xmarks is a tool used to synchronize favorites. I usually use it to synchronize favorites of IE, firefox, and chrome.

First open the following location in the registry,

32-bit operating system: HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Uninstall \

Note: For a 64-bit operating system:

The 64-bit program is still in: HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Uninstall \

The 32-bit program is in: HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node \ Microsoft \ Windows \ CurrentVersion \ Uninstall \

 

There are many registry subkeys under Uninstall. You need to patiently search for "DisplayName" one by one to find the program's ProductCode, such.

From the registry we find the UninstallString key value: MsiExec.exe/X {C56BBAC8-0DD2-4CE4-86E0-F2BDEABDD0CF}, then ProductCode is {C56BBAC8-0DD2-4CE4-86E0-F2BDEABDD0CF}

You can run the MsiExec.exe/X {ProductCode} command to uninstall the program.

The unmount command should be MsiExec.exe/X {C56BBAC8-0DD2-4CE4-86E0-F2BDEABDD0CF}

Then, directly call this command in CMD. A dialog box is displayed. Click "yes" to uninstall the software.

In automated testing, we do not want to bring up this dialog box, but want to uninstall it directly. At the same time, you do not need to add two parameters/quiet/norestart to restart the system.

The current unmount command is: MsiExec.exe/X {C56BBAC8-0DD2-4CE4-86E0-F2BDEABDD0CF}/quiet

 

C # uninstall the program

C # code uninstallation is relatively simple. Of course, you can also use other languages.

            Process p = new Process();            p.StartInfo.FileName = "msiexec.exe";            p.StartInfo.Arguments = "/x {C56BBAC8-0DD2-4CE4-86E0-F2BDEABDD0CF} /quiet /norestart";            p.Start(); 

 

C # search for ProductCode in the Registry

The most troublesome thing is how to obtain ProductCode from the registry. For automated testing of non-Web programs, you often need to deal with the Registry.

Code:

Public static string GetProductCode (string displayName) {string productCode = string. empty; // if it is a 32-bit operating system (or the system is 64-bit, the program is also 64-bit) string bit32 = @ "SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Uninstall "; // If the operating system is 64-bit and the program is 32-Bit string bit64 = @ "SOFTWARE \ Wow6432Node \ Microsoft \ Windows \ CurrentVersion \ Uninstall"; RegistryKey localMachine = Registry. localMachine; RegistryKey Uninstall = localMachine. openSubKey (bit32, true); foreach (string subkey in Uninstall. getSubKeyNames () {RegistryKey productcode = Uninstall. openSubKey (subkey); try {string displayname = productcode. getValue ("DisplayName "). toString (); if (displayname = displayName) {string uninstallString = productcode. getValue ("UninstallString "). toString (); string [] strs = uninstallString. split (new char [2] {','}); productCode = strs [1]; return productCode ;}} catch {}} return productCode ;}

 

Complete source code download

Click here to download the complete source code. Open it with vs2010 or later.

 

 

 
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.