Forum Discussion

ameett's avatar
ameett
Contributor
10 years ago
Solved

Install and Uninstall an application through the script.

How to Install and Uninstall an application through the script?........for eg. A  .msi application. I am using C# script.

 

Thanks

ameett

  • If you need to just silently install the MSI file, and not test the installer, you can use the Win32_Product.Install method:

     

    var strMSIPath = "C:\\MyAppSetup.msi";
    var strOptions = ""; // MSI properties in the format "PROPERTY1=value1 PROPERTY2=value2"
    var ForAllUsers = false;
    
    var oSoftware = GetObject("winmgmts:").Get("Win32_Product");
    var res = oSoftware.Install(strMSIPath, strOptions, ForAllUsers);
    
    if (res != 0)
      Log.Error("Could not install the MSI file. Error " + res);
    // For error codes, see MSDN: // https://msdn.microsoft.com/en-us/library/aa390890(v=vs.85).aspx

     

    To uninstall an application, try this example: Uninstall an application.
    Use the application name as shown in Programs and Features.

1 Reply

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    If you need to just silently install the MSI file, and not test the installer, you can use the Win32_Product.Install method:

     

    var strMSIPath = "C:\\MyAppSetup.msi";
    var strOptions = ""; // MSI properties in the format "PROPERTY1=value1 PROPERTY2=value2"
    var ForAllUsers = false;
    
    var oSoftware = GetObject("winmgmts:").Get("Win32_Product");
    var res = oSoftware.Install(strMSIPath, strOptions, ForAllUsers);
    
    if (res != 0)
      Log.Error("Could not install the MSI file. Error " + res);
    // For error codes, see MSDN: // https://msdn.microsoft.com/en-us/library/aa390890(v=vs.85).aspx

     

    To uninstall an application, try this example: Uninstall an application.
    Use the application name as shown in Programs and Features.