Mit wenigen Zeile code aus einer Anwendung heraus eine installierte Anwendung deinstallieren (Quick and Dirty Lösung).
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sName As String = String.Empty
Dim sMachineName As String = String.Empty
Dim sAdminUser As String = String.Empty
Dim sPassword As String = String.Empty
Dim oService As Object
Dim oLocator As Object
sMachineName = InputBox("Bitte geben Sie den Computern an!")
sAdminUser = InputBox("Enter the admin user name.")
sPassword = InputBox("Enter the users password. ")
oLocator = CreateObject("WbemScripting.SWbemLocator")
'connect to remote machine
oService = oLocator.ConnectServer(sMachineName, "root\cimv2", sAdminUser, sPassword)
'get a list of installed products
Dim sMsg As String = String.Empty
For Each oProduct As Object In GetObject("winmgmts:{impersonationLevel=impersonate,(Debug)}").InstancesOf("win32_Product")
'Wollen wir wirklich das Ausgewählte Produkt deinstallieren?
sMsg = "Product: " & vbCrLf
sMsg = sMsg & oProduct.Name
sMsg = sMsg & vbCrLf & "Continue uninstalling?"
If MsgBox(sMsg, 4) = 6 Then
sName = oProduct.Name
Exit For
End If
Next
Try
'Get the named package of the selected Product
For Each oProduct As Object In GetObject( _
"winmgmts:{impersonationLevel=impersonate}" _
).ExecQuery _
("Select * from Win32_Product where Name='" & sName & "'")
'uninstall selected Product
oProduct.Uninstall()
'done!
MessageBox.Show("Uninstalled " & sName, "Operation Complete", MessageBoxButtons.OK)
Next
Catch ex As Exception
MessageBox.Show(ex.Message & sName, "Operation NOT Completed", MessageBoxButtons.OK)
End Try
End Sub
Kommentare zum Snippet