C # _ 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.

 

Appendix: automated test series tutorials (coming soon)

Automated Testing (I) 12306 automated logon tool for train ticket websites

Automated Testing (ii) plug-ins for continuous view

Automated Testing (iii) Web automated testing principles

Automated Testing (4) Automatic Software Uninstall

Automated test (5) read and write the registry of a 64-bit Operating System

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.