Searching for X software is installed or not using VBScript

G

Guest

Hello,

I would like check if "SharpReader 0.9.6.0" is installed in my workstation
or not.
I have tried to use one script from MS site. It is not working or I have
goofed some where. I need help....

-------------------
dim objComputer
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'SharpReader 0.9.6.0'")

For Each objSoftware in colSoftware
Wscript.Echo objComputer.MachineName
'objSoftware.Uninstall()
Next
----------------------
 
R

Ramesh, MS-MVP

Try this example:
===========================================================
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'Microsoft Office 2000
Premium'")

If colSoftware.count > 0 Then
WScript.Echo "Microsoft Office 2000 is installed"
Else
WScript.Echo "Microsoft Office 2000 is NOT installed"
End If
===========================================================


Or this one. Enumerates the entire list, and then verifies each item.
==========================================================
On Error Resume Next
IsInstalled = 0
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Product")

For Each objItem in colItems
If InStr(objItem.Name, "Office 2000") > 0 Then
IsInstalled = 1
End If
Next

If IsInstalled = 1 Then
WScript.Echo "Office 2000 is installed"
Else
WScript.Echo "Office 2000 is NOT installed"
End If

=========================================================
--
Regards,

Ramesh Srinivasan, Microsoft MVP [Windows XP Shell/User]
Windows® XP Troubleshooting http://www.winhelponline.com


Hello,

I would like check if "SharpReader 0.9.6.0" is installed in my workstation
or not.
I have tried to use one script from MS site. It is not working or I have
goofed some where. I need help....

-------------------
dim objComputer
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'SharpReader 0.9.6.0'")

For Each objSoftware in colSoftware
Wscript.Echo objComputer.MachineName
'objSoftware.Uninstall()
Next
----------------------
 
G

Guest

Hello,

I tried using this script by replacing Office 2000 with 2003 and it works.
But when I use SharpReader 0.9.6.0 as application name it does not work. But
I am getting this application name using following script so I dont think
there should be any problem with the name atleast. Strange it is.....

-----------------------
Option Explicit
Dim strComputer, strKey, strSubKey
Dim objRegistry
Dim arrSubKeys()
Dim objComputer
Dim strDisplayName, strDisplayVersion, strInstallLocation
Const HKEY_LOCAL_MACHINE = &H80000002


Dim fso, tf,ctr
ctr=0
Set fso = CreateObject("Scripting.FileSystemObject")

strComputer = "."
strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
Set objComputer = CreateObject("Shell.LocalMachine")

Set objRegistry = GetObject("winmgmts:" & _
"{impersonationLevel=Impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKey, arrSubKeys

On Error Resume Next
For Each strSubKey In arrSubKeys
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, _
strKey & "\" & strSubKey, "DisplayName", strDisplayName
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, _
strKey & "\" & strSubKey, "DisplayVersion", strDisplayVersion
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, _
strKey & "\" & strSubKey, "InstallLocation", strInstallLocation

if ctr = 0 then
Set tf = fso.CreateTextFile("\\advad03\Profiles\Applications\" +
objComputer.MachineName + ".txt", True)
ctr=1
end if
'tf.WriteLine strSubKey
'tf.WriteLine String(Len(strSubKey), "-")
tf.WriteLine strDisplayName
'tf.WriteLine "Display name: " & strDisplayName
'tf.WriteLine "Display version: " & strDisplayVersion
'tf.WriteLine "Install location: " & strInstallLocation
'tf.WriteLine
strDisplayName = vbEmpty
strDisplayVersion = vbEmpty
strInstallLocation = vbEmpty
Next
------------------------------------------
Ramesh said:
Try this example:
===========================================================
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'Microsoft Office 2000
Premium'")

If colSoftware.count > 0 Then
WScript.Echo "Microsoft Office 2000 is installed"
Else
WScript.Echo "Microsoft Office 2000 is NOT installed"
End If
===========================================================


Or this one. Enumerates the entire list, and then verifies each item.
==========================================================
On Error Resume Next
IsInstalled = 0
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Product")

For Each objItem in colItems
If InStr(objItem.Name, "Office 2000") > 0 Then
IsInstalled = 1
End If
Next

If IsInstalled = 1 Then
WScript.Echo "Office 2000 is installed"
Else
WScript.Echo "Office 2000 is NOT installed"
End If

=========================================================
--
Regards,

Ramesh Srinivasan, Microsoft MVP [Windows XP Shell/User]
Windows® XP Troubleshooting http://www.winhelponline.com


Hello,

I would like check if "SharpReader 0.9.6.0" is installed in my workstation
or not.
I have tried to use one script from MS site. It is not working or I have
goofed some where. I need help....

-------------------
dim objComputer
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'SharpReader 0.9.6.0'")

For Each objSoftware in colSoftware
Wscript.Echo objComputer.MachineName
'objSoftware.Uninstall()
Next
 
R

Ramesh, MS-MVP

Do you know if SharpReader uses Windows Installer? If not, the Win32_Product
thing may not work.

SharpReader 0.9.6.0

If it uses Windows Installer, then you can modify the first script, and use
the LIKE operator to query Product names that contains the string
"SharpReader".

Anyway, I'm glad you found another method to accomplish the task.

--
Regards,

Ramesh Srinivasan, Microsoft MVP [Windows XP Shell/User]
Windows® XP Troubleshooting http://www.winhelponline.com


Hello,

I tried using this script by replacing Office 2000 with 2003 and it works.
But when I use SharpReader 0.9.6.0 as application name it does not work. But
I am getting this application name using following script so I dont think
there should be any problem with the name atleast. Strange it is.....

-----------------------
Option Explicit
Dim strComputer, strKey, strSubKey
Dim objRegistry
Dim arrSubKeys()
Dim objComputer
Dim strDisplayName, strDisplayVersion, strInstallLocation
Const HKEY_LOCAL_MACHINE = &H80000002


Dim fso, tf,ctr
ctr=0
Set fso = CreateObject("Scripting.FileSystemObject")

strComputer = "."
strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
Set objComputer = CreateObject("Shell.LocalMachine")

Set objRegistry = GetObject("winmgmts:" & _
"{impersonationLevel=Impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKey, arrSubKeys

On Error Resume Next
For Each strSubKey In arrSubKeys
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, _
strKey & "\" & strSubKey, "DisplayName", strDisplayName
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, _
strKey & "\" & strSubKey, "DisplayVersion", strDisplayVersion
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, _
strKey & "\" & strSubKey, "InstallLocation", strInstallLocation

if ctr = 0 then
Set tf = fso.CreateTextFile("\\advad03\Profiles\Applications\" +
objComputer.MachineName + ".txt", True)
ctr=1
end if
'tf.WriteLine strSubKey
'tf.WriteLine String(Len(strSubKey), "-")
tf.WriteLine strDisplayName
'tf.WriteLine "Display name: " & strDisplayName
'tf.WriteLine "Display version: " & strDisplayVersion
'tf.WriteLine "Install location: " & strInstallLocation
'tf.WriteLine
strDisplayName = vbEmpty
strDisplayVersion = vbEmpty
strInstallLocation = vbEmpty
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top