473,748 Members | 2,207 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("winm gmts:
{impersonationL evel=impersonat e}!\\" & frmMain.Compute rName & "\root
\cimv2")
Set colSoftware = objWMIService.e xecquery("Selec t * from
Win32_Product Where Name = '" & ApptoUninst & "'")
For Each objSoftware In colSoftware
frmStatus.lblSt atus.Caption = "Uninstalli ng " &
lstApplications .Text & ". Please Wait...."
objSoftware.Uni nstall
If Err.Number = 0 Then
frmStatus.lblSt atus.Caption = "Uninstall
Complete."
Call frmMain.cmdApps _Click
frmStatus.Hide
Else
MsgBox "Error: " & Err.Description
frmStatus.Hide
End If
Next
VB.NET Code
Dim myConnectionOpt ions As New System.Manageme nt.ConnectionOp tions
With myConnectionOpt ions
.Impersonation =
System.Manageme nt.Impersonatio nLevel.Imperson ate
.Authentication =
System.Manageme nt.Authenticati onLevel.Packet
End With
Dim myManagementSco pe As System.Manageme nt.ManagementSc ope
myManagementSco pe = New System.Manageme nt.ManagementSc ope("\
\"
& FrmMain.Compute rName & "\root\cimv 2")
myManagementSco pe.Connect()
If myManagementSco pe.IsConnected = False Then
MsgBox("Could not connect to WMI namespace")
Exit Sub
End If
Dim myObjectSearche r As
System.Manageme nt.ManagementOb jectSearcher
Dim myCollection As
System.Manageme nt.ManagementOb jectCollection
Dim myObject As System.Manageme nt.ManagementOb ject
Dim ApptoUninst As String
ApptoUninst =
Trim(DGVApps.Se lectedRows.Item (0).Cells("AppN ame").Value)
myObjectSearche r = New
System.Manageme nt.ManagementOb jectSearcher(my ManagementScope .Path.ToString,
"Select * From Win32_Product Where Name = '" & ApptoUninst & "'")
myCollection = myObjectSearche r.Get()
For Each myObject In myCollection
If myObject.GetPro pertyValue("Cap tion") = ApptoUninst
Then
frmStatus.lblSt atus.Text = "Uninstalli ng " &
ApptoUninst & ". Please Wait...."
frmStatus.Show( )
''''''''''''''' '''''''' I THINK THE UNINSTALL CODE SHOULD GO HERE
''''''''''''''' ''''''''''''''' ''''''''''
myObject.Invoke Method("Uninsta ll", Nothing) < - LINE DOESN'T WORK IT
THROWS AND EXCEPTION
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' *'''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' '*''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''*'''''''''
If Err.Number = 0 Then
MsgBox("Uninsta ll Complete!", MsgBoxStyle.OkO nly,
"Success")
frmStatus.Hide( )
Else
MsgBox("Error: " & Err.Number & " : " &
Err.Description )
frmStatus.Hide( )
Exit For
End If
End If
Sep 23 '08 #1
1 8494
"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("winm gmts:
{impersonationL evel=impersonat e}!\\" & frmMain.Compute rName & "\root
\cimv2")
Set colSoftware = objWMIService.e xecquery("Selec t * from
Win32_Product Where Name = '" & ApptoUninst & "'")
For Each objSoftware In colSoftware
frmStatus.lblSt atus.Caption = "Uninstalli ng " &
lstApplications .Text & ". Please Wait...."
objSoftware.Uni nstall
If Err.Number = 0 Then
frmStatus.lblSt atus.Caption = "Uninstall
Complete."
Call frmMain.cmdApps _Click
frmStatus.Hide
Else
MsgBox "Error: " & Err.Description
frmStatus.Hide
End If
Next
VB.NET Code
Dim myConnectionOpt ions As New System.Manageme nt.ConnectionOp tions
With myConnectionOpt ions
.Impersonation =
System.Manageme nt.Impersonatio nLevel.Imperson ate
.Authentication =
System.Manageme nt.Authenticati onLevel.Packet
End With
Dim myManagementSco pe As System.Manageme nt.ManagementSc ope
myManagementSco pe = New System.Manageme nt.ManagementSc ope("\
\"
& FrmMain.Compute rName & "\root\cimv 2")
myManagementSco pe.Connect()
If myManagementSco pe.IsConnected = False Then
MsgBox("Could not connect to WMI namespace")
Exit Sub
End If
Dim myObjectSearche r As
System.Manageme nt.ManagementOb jectSearcher
Dim myCollection As
System.Manageme nt.ManagementOb jectCollection
Dim myObject As System.Manageme nt.ManagementOb ject
Dim ApptoUninst As String
ApptoUninst =
Trim(DGVApps.Se lectedRows.Item (0).Cells("AppN ame").Value)
myObjectSearche r = New
System.Manageme nt.ManagementOb jectSearcher(my ManagementScope .Path.ToString,
"Select * From Win32_Product Where Name = '" & ApptoUninst & "'")
myCollection = myObjectSearche r.Get()
For Each myObject In myCollection
If myObject.GetPro pertyValue("Cap tion") = ApptoUninst
Then
frmStatus.lblSt atus.Text = "Uninstalli ng " &
ApptoUninst & ". Please Wait...."
frmStatus.Show( )
''''''''''''''' '''''''' I THINK THE UNINSTALL CODE SHOULD GO HERE
''''''''''''''' ''''''''''''''' ''''''''''
myObject.Invoke Method("Uninsta ll", Nothing) < - LINE DOESN'T WORK IT
THROWS AND EXCEPTION
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' Â*''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''Â*''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''Â*'''''''''
If Err.Number = 0 Then
MsgBox("Uninsta ll Complete!", MsgBoxStyle.OkO nly,
"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
27703
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 to do this?.. Thanks for any help... Bryan
5
20393
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, and I know this is all stored in the registry. But short of searching through the entire registry, I cannot figure out how to locate the program. I see that in the registry (for .msi) installs, stores something like:...
0
1874
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 uninstall only the products installed by MSI. How I can uninstal the other products ? Thank you *** Sent via Developersdex http://www.developersdex.com ***
1
2428
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 this to gather the UninstallString: keyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + subKey; keyName = "DisplayName";
1
1622
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 you click Add or Remove Programs in the control panel. I have some applications in an install base that I not longer have the setup.exe file (Installshield express) for. If I had that, I could just use the command line switches to do it but alas,...
1
2565
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" menu > programs, as well as write application name in Registry. How to uninstall script encoder safely and correctly, include windows "Start" menu entries? Thanks,
5
6467
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 http://www.ww2airborne.net/
3
15588
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 some sort of version conflict. Any help is appreciated.
2
2788
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? Thanks Freddy
0
8831
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9326
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4877
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.