EN
此内容没有您的语言版本,但有英语版本。

Uninstall method of the Win32_Product class

The Uninstall WMI class method uninstalls the associated instance of Win32_Product.

Note  For more information about support or requirements for installation on a specific operating system, see Operating System Availability of WMI Components.

This topic uses Managed Object Format (MOF) syntax. For more information about using this method see Calling a Method.

Syntax


uint32 Uninstall();

Parameters

This method has no parameters.

Return value

Return codeDescription
0

Successful completion

2147549445

RPC Server Fault Error

 

Remarks

Software installation is rarely permanent; instead, software is typically removed at some point in time, and for any number of reasons:

  • The functionality supplied by the software is no longer needed.
  • The software is being replaced by a competing software package.
  • The software is not licensed for use in the organization.
  • The software is installed on the wrong computer.

The Win32_Product Uninstall method can be used to remove software from a computer.

The Uninstall method can be used either on the local computer or on a remote computer, and without delegation. This is because no multihop security operations are involved. Instead, the software is simply removed from the computer.

Although the Uninstall method can remove software from a computer, it does not override Group Policy. For example, if Microsoft Excel has been installed on a computer, you can use the Uninstall method to remove it. However, if Microsoft Excel is available to the user through Group Policy, the user will be able to reinstall the application.

Examples

The following VBScript sample deletes software on a computer


strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_Product WHERE Name = 'Personnel database'")
For Each objSoftware in colSoftware
 objSoftware.Uninstall()
Next

The following PowerShell code sample describes how to uninstall an application from multiple computers.


$list = 'host1','host2','host3'   # your hosts go here
$name = 'appname'                 # your application name goes here (as displayed by win32_product instance)
$list | foreach {
    $hostname = $_
    gwmi win32_product -filter "Name = '$name'" -namespace root/cimv2 -comp $_ | foreach {
        if ($_.uninstall().returnvalue -eq 0) { write-host "Successfully uninstalled $name from $($hostname)" }
        else { write-warning "Failed to uninstall $name from $($hostname)." }
    }
}

Requirements

Minimum supported client

Windows XP

Minimum supported server

Windows Server 2003

Namespace

\root\CIMV2

MOF

Msi.mof

DLL

Msiprov.dll

See also

Installed Applications Classes
Win32_Product
WMI Tasks: Computer Software

 

 

社区附加资源

显示:
© 2014 Microsoft