473,326 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

VB.NET using WMI to uninstall programs remotely

Hey all,

i'm currently working on a project for our IT group. what this
program
does is lists all the installed programs on the remote machine for
the
admin. what i'm trying to add is functionality for the admin to
select
a program from the list and click an uninstall button on the program
to uninstall the program remotely. We are rebuilding this program
from
VB6 into a .net environment. below is the VB6 code and the VB.NET
code
that i'm currently using to try and replicate the same functionality.
any ideas or help is welcome.
Thanks,
Luke
VB6 Code
Set objWMIService = GetObject("winmgmts:
{impersonationLevel=impersonate}!\\" & frmMain.ComputerName & "\root
\cimv2")
Set colSoftware = objWMIService.execquery("Select * from
Win32_Product Where Name = '" & ApptoUninst & "'")
For Each objSoftware In colSoftware
frmStatus.lblStatus.Caption = "Uninstalling " &
lstApplications.Text & ". Please Wait...."
objSoftware.Uninstall
If Err.Number = 0 Then
frmStatus.lblStatus.Caption = "Uninstall
Complete."
Call frmMain.cmdApps_Click
frmStatus.Hide
Else
MsgBox "Error: " & Err.Description
frmStatus.Hide
End If
Next
VB.NET Code
Dim myConnectionOptions As New System.Management.ConnectionOptions
With myConnectionOptions
.Impersonation =
System.Management.ImpersonationLevel.Impersonate
.Authentication =
System.Management.AuthenticationLevel.Packet
End With
Dim myManagementScope As System.Management.ManagementScope
myManagementScope = New System.Management.ManagementScope("\
\"
& FrmMain.ComputerName & "\root\cimv2")
myManagementScope.Connect()
If myManagementScope.IsConnected = False Then
MsgBox("Could not connect to WMI namespace")
Exit Sub
End If
Dim myObjectSearcher As
System.Management.ManagementObjectSearcher
Dim myCollection As
System.Management.ManagementObjectCollection
Dim myObject As System.Management.ManagementObject
Dim ApptoUninst As String
ApptoUninst =
Trim(DGVApps.SelectedRows.Item(0).Cells("AppName") .Value)
myObjectSearcher = New
System.Management.ManagementObjectSearcher(myManag ementScope.Path.ToString,
"Select * From Win32_Product Where Name = '" & ApptoUninst & "'")
myCollection = myObjectSearcher.Get()
For Each myObject In myCollection
If myObject.GetPropertyValue("Caption") = ApptoUninst
Then
frmStatus.lblStatus.Text = "Uninstalling " &
ApptoUninst & ". Please Wait...."
frmStatus.Show()
''''''''''''''''''''''' I THINK THE UNINSTALL CODE SHOULD GO HERE
''''''''''''''''''''''''''''''''''''''''
myObject.InvokeMethod("Uninstall", Nothing) < - LINE DOESN'T WORK IT
THROWS AND EXCEPTION
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''*'''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '*'''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''*'''''''''
If Err.Number = 0 Then
MsgBox("Uninstall Complete!", MsgBoxStyle.OkOnly,
"Success")
frmStatus.Hide()
Else
MsgBox("Error: " & Err.Number & " : " &
Err.Description)
frmStatus.Hide()
Exit For
End If
End If
Sep 23 '08 #1
1 8452
"Luke" wrote:
Hey all,

i'm currently working on a project for our IT group. what this
program
does is lists all the installed programs on the remote machine for
the
admin. what i'm trying to add is functionality for the admin to
select
a program from the list and click an uninstall button on the program
to uninstall the program remotely. We are rebuilding this program
from
VB6 into a .net environment. below is the VB6 code and the VB.NET
code
that i'm currently using to try and replicate the same functionality.
any ideas or help is welcome.
Thanks,
Luke
VB6 Code
Set objWMIService = GetObject("winmgmts:
{impersonationLevel=impersonate}!\\" & frmMain.ComputerName & "\root
\cimv2")
Set colSoftware = objWMIService.execquery("Select * from
Win32_Product Where Name = '" & ApptoUninst & "'")
For Each objSoftware In colSoftware
frmStatus.lblStatus.Caption = "Uninstalling " &
lstApplications.Text & ". Please Wait...."
objSoftware.Uninstall
If Err.Number = 0 Then
frmStatus.lblStatus.Caption = "Uninstall
Complete."
Call frmMain.cmdApps_Click
frmStatus.Hide
Else
MsgBox "Error: " & Err.Description
frmStatus.Hide
End If
Next
VB.NET Code
Dim myConnectionOptions As New System.Management.ConnectionOptions
With myConnectionOptions
.Impersonation =
System.Management.ImpersonationLevel.Impersonate
.Authentication =
System.Management.AuthenticationLevel.Packet
End With
Dim myManagementScope As System.Management.ManagementScope
myManagementScope = New System.Management.ManagementScope("\
\"
& FrmMain.ComputerName & "\root\cimv2")
myManagementScope.Connect()
If myManagementScope.IsConnected = False Then
MsgBox("Could not connect to WMI namespace")
Exit Sub
End If
Dim myObjectSearcher As
System.Management.ManagementObjectSearcher
Dim myCollection As
System.Management.ManagementObjectCollection
Dim myObject As System.Management.ManagementObject
Dim ApptoUninst As String
ApptoUninst =
Trim(DGVApps.SelectedRows.Item(0).Cells("AppName") .Value)
myObjectSearcher = New
System.Management.ManagementObjectSearcher(myManag ementScope.Path.ToString,
"Select * From Win32_Product Where Name = '" & ApptoUninst & "'")
myCollection = myObjectSearcher.Get()
For Each myObject In myCollection
If myObject.GetPropertyValue("Caption") = ApptoUninst
Then
frmStatus.lblStatus.Text = "Uninstalling " &
ApptoUninst & ". Please Wait...."
frmStatus.Show()
''''''''''''''''''''''' I THINK THE UNINSTALL CODE SHOULD GO HERE
''''''''''''''''''''''''''''''''''''''''
myObject.InvokeMethod("Uninstall", Nothing) < - LINE DOESN'T WORK IT
THROWS AND EXCEPTION
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''Â*''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' ''Â*'''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''Â*'''''''''
If Err.Number = 0 Then
MsgBox("Uninstall Complete!", MsgBoxStyle.OkOnly,
"Success")
frmStatus.Hide()
Else
MsgBox("Error: " & Err.Number & " : " &
Err.Description)
frmStatus.Hide()
Exit For
End If
End If

What exception is thrown?
Does the code work locally?
--
urkec
Sep 24 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Bryan | last post by:
I am writing a C# program that needs to see if a particular program is installed (it would be listed in the "Add or Remove Programs" list from the Control Panel) and uninstall it. Is there a way...
5
by: Adam Clauss | last post by:
I am needing to automate some installation tasks. I first need to determine if there is already a version of a program installed. The program appears in the Add/Remove Programs in control panel,...
0
by: Dan Pavel | last post by:
Hi, I need to build an small application to uninstall a app remotely from the computers in my network. How I can do this through WMI. If I use SELECT "app_name" FROM Win32_Product I can...
1
by: Dan Pavel | last post by:
Hi, I need to build an small application to uninstall an application, remotely, from the computers in my network. How I can do this through WMI. It is not an application installed by MSI. I use...
1
by: Steve Long | last post by:
Hello all, is there a way to programatically uninstall a program via one of the Windows Management classes or one of the Win32 classes? I'm looking for a way to invoke the process that occurs when...
1
by: mistral | last post by:
How to uninstall windows script encoder (screnc.exe)? There are no entries in Add/Remove programs in Control Panel. However, its a single exe, but installer create program name in windows "Start"...
5
by: Screaming Eagles 101 | last post by:
Hi , not much trouble in making a setup project, but I'd like also an icon in All Programs to uninstall the application. I can't find a good explanation on the net so far... -- Filip...
3
by: Steve Cross | last post by:
I need a procedure for a manual .Net 2.0 Framework uninstall. dotnetfx /C doesn't work Manaully running the .msi from the %systemroot%\installer directory doesn't work. It appears to be...
2
by: =?Utf-8?B?ZnJlZGR5?= | last post by:
I would like to uninstall app form both local and remote computers without the user knowing what is going on. I have admin right to all the computers so this is not a problem. Can this be done? ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.