Hello, I'm trying to write a script to find out whether MS
Installer 3.0, Microsoft Security Bulletin MS04-011( KB 835732 ), .NET
Framework2.0 SP1. I've written a script using Win32_Product class to
find out whether Mozilla is installer or not ( Just to check whether
script is working or not) and for some reason its not working. How to
find out for the softwares that are not showing up in Add or remove
window? Please advise. Any help on this highly appreciated. And can we check for multiple softwares in one WMI query?? Below is the code. I'm checking it first on my local machine. Const WbemAuthenticationLevelPktPrivacy = 4 Set FileObj = CreateObject("Scripting.FileSystemObject") set Logfile = Fileobj.openTextFile("SoftwareLog.CSV",ForAppending, True) ServerName="." Const wbemFlagReturnImmediately = &h10 Const wbemFlagForwardOnly = &h20 Const ForAppending = 8 softwares(servername) Sub Softwares(Servername) On Error Resume Next Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!" & servername & "rootcimv2") if err.number<>0 then LogFile.write Servername & ",Error,"&err.number&","&err.description & "," &"ERROR" wscript.echo err.number&"-"&err.description exit sub end if Set colInstProducts = objWMIService.ExecQuery ("Select * from Win32_Product where name = '%Mozilla%'") If err.number<>0 then LogFile.write Servername & "," & err.number & "," & err.description WScript.echo err.number&"-"&err.description Else For Each objProduct in colInstProducts
Logfile.WriteLine Servername & "," & objProduct.Name &
",Version " & objProduct.Version& "," &
objProduct.installdate Next End if End Sub Logfile.close Wscript.echo "Completed...."
finding out softwares
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- superfly12
- Posts: 133
- Last visit: Sun Nov 02, 2014 4:37 pm
finding out softwares
Hello, I'm trying to write a script to find out whether MS
Installer 3.0, Microsoft Security Bulletin MS04-011( KB 835732 ), .NET
Framework2.0 SP1. I've written a script using Win32_Product class to
find out whether Mozilla is installer or not ( Just to check whether
script is working or not) and for some reason its not working. How to
find out for the softwares that are not showing up in Add or remove
window? Please advise. Any help on this highly appreciated. And can we check for multiple softwares in one WMI query?? Below is the code. I'm checking it first on my local machine. Const WbemAuthenticationLevelPktPrivacy = 4 Set FileObj = CreateObject("Scripting.FileSystemObject") set Logfile = Fileobj.openTextFile("SoftwareLog.CSV",ForAppending, True) ServerName="." Const wbemFlagReturnImmediately = &h10 Const wbemFlagForwardOnly = &h20 Const ForAppending = 8 softwares(servername) Sub Softwares(Servername) On Error Resume Next Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!" & servername & "rootcimv2") if err.number<>0 then LogFile.write Servername & ",Error,"&err.number&","&err.description & "," &"ERROR" wscript.echo err.number&"-"&err.description exit sub end if Set colInstProducts = objWMIService.ExecQuery ("Select * from Win32_Product where name = '%Mozilla%'") If err.number<>0 then LogFile.write Servername & "," & err.number & "," & err.description WScript.echo err.number&"-"&err.description Else For Each objProduct in colInstProducts
Logfile.WriteLine Servername & "," & objProduct.Name &
",Version " & objProduct.Version& "," &
objProduct.installdate Next End if End Sub Logfile.close Wscript.echo "Completed...."
Installer 3.0, Microsoft Security Bulletin MS04-011( KB 835732 ), .NET
Framework2.0 SP1. I've written a script using Win32_Product class to
find out whether Mozilla is installer or not ( Just to check whether
script is working or not) and for some reason its not working. How to
find out for the softwares that are not showing up in Add or remove
window? Please advise. Any help on this highly appreciated. And can we check for multiple softwares in one WMI query?? Below is the code. I'm checking it first on my local machine. Const WbemAuthenticationLevelPktPrivacy = 4 Set FileObj = CreateObject("Scripting.FileSystemObject") set Logfile = Fileobj.openTextFile("SoftwareLog.CSV",ForAppending, True) ServerName="." Const wbemFlagReturnImmediately = &h10 Const wbemFlagForwardOnly = &h20 Const ForAppending = 8 softwares(servername) Sub Softwares(Servername) On Error Resume Next Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!" & servername & "rootcimv2") if err.number<>0 then LogFile.write Servername & ",Error,"&err.number&","&err.description & "," &"ERROR" wscript.echo err.number&"-"&err.description exit sub end if Set colInstProducts = objWMIService.ExecQuery ("Select * from Win32_Product where name = '%Mozilla%'") If err.number<>0 then LogFile.write Servername & "," & err.number & "," & err.description WScript.echo err.number&"-"&err.description Else For Each objProduct in colInstProducts
Logfile.WriteLine Servername & "," & objProduct.Name &
",Version " & objProduct.Version& "," &
objProduct.installdate Next End if End Sub Logfile.close Wscript.echo "Completed...."
finding out softwares
It will work on XP SP2
Test with this:
I think FireFox is not called Mozilla.
Test with this:
Code: Select all
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!.rootcimv2")
Set colInstProducts = objWMIService.ExecQuery ("Select * from Win32_Product")
For Each objProduct in colInstProducts
WScript.Echo objProduct.Name & ",Version " & objProduct.Version& "," & objProduct.installdate
Next
I think FireFox is not called Mozilla.
finding out softwares
Here's the basic code to parse the registry. I have 64bit boxes, so I have an extra key to search, so if that is not the case for you can remove that aspect and the On Error Resume Next too...
Code: Select all
Const HKLM = &H80000002
strComputer = "."
Set objReg = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv")
arrSearchKeys = Array("SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall", "SOFTWAREMicrosoftWindowsCurrentVersionUninstall")
For Each key in arrSearchKeys
On Error Resume Next
objReg.EnumKey HKLM, key, arrSubKeys
For Each subkey In arrSubKeys
objReg.GetStringValue HKLM, key & "" & SubKey, "DisplayName", strDispName
objReg.GetStringValue HKLM, key & "" & SubKey, "DisplayVersion", strVer
If strVer "" Then WScript.Echo strDispName & ";" & strVer
Next
Next
finding out softwares
If (strVer <> "") And (InStr(UCase(strDispName), "ADOBE")) Then WScript.Echo strDispName & ";" & strVer
finding out softwares
There are numerous ways to do things, but I would convert most of the functionality into a sub. The problem with this way is that I'm enumerating the reg key 3 times, but hey....it works:
Code: Select all
Const HKLM = &H80000002
strComputer = "."
Set objReg = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv")
arrSoftwareToFind = Array("WINDOWS INSTALLER 3.1", ".NET FRAMEWORK 2.0", "KB835732")
For each strSoftware in arrSoftwareToFind
Find_Software strSoftware
Next
Sub Find_Software(software)
On Error Resume Next
blnFound = False
arrSearchKeys = Array("SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall", "SOFTWAREMicrosoftWindowsCurrentVersionUninstall")
For Each key in arrSearchKeys
objReg.EnumKey HKLM, key, arrSubKeys
For Each subkey In arrSubKeys
objReg.GetStringValue HKLM, key & "" & SubKey, "DisplayName", strDispName
objReg.GetStringValue HKLM, key & "" & SubKey, "DisplayVersion", strVer
If strVer "" And (InStr(UCase(strDispName), UCase(software))) Then
WScript.Echo strDispName & ";" & strVer
blnFound = True
End If
Next
Next
If blnFound = False Then WScript.Echo "Unable to find software: " & software
End Sub
- Gyorgy Nemesmagasi
- Posts: 50
- Last visit: Wed Mar 16, 2022 12:58 pm
finding out softwares
It would be much easier if you describe what kind of error message(s) you had and what you missed from the output etc..
Please find my notes below based on the code itself:- The ForAppending variable haven't got a value (ForAppending = 8)- The variable declaration is completely missing; it caused the next error also - The objReg in the Find_Software Sub hasn't got an object (the 424 error suppressed by the On Error Resume Next). You need to declarate it as a global variable or give it to the sub as a parameter when it called.- You can use WriteLine <text> instead of Write <text> & vbCrLf- You missed a Trim form the ReadLine, it no cause a problem if your input file is well constructed but if there is a mistyped space or enter the script will fail.- It requires calling the Close method for the properly close the files.
What can you do now:- So at first decelerate the variables in the rigth palace and switch off the error suppression. You can use the Option Explicit statement for find undeclarated variables.- Based on the error messages you can fix the code step-by-step.- If the script works you can test it with misstyped input file, missing server etc. for add a basic error tolerance.- Keep in mind the registry provider requires admin rights on the target computer and the firewalls/routers my prevent the connection.
VBScript Variables & scopehttp://msdn.microsoft.com/en-us/library/t7zd6etz(VS.85).aspx
FileSystemObject Objecthttp://msdn.microsoft.com/en-us/library/6kxy1a51(VS.85).aspx
You can find more information in the Windows Script 5.6 Documentationhttp://www.microsoft.com/DOWNLOADS/details.asp ... laylang=en
Please find my notes below based on the code itself:- The ForAppending variable haven't got a value (ForAppending = 8)- The variable declaration is completely missing; it caused the next error also - The objReg in the Find_Software Sub hasn't got an object (the 424 error suppressed by the On Error Resume Next). You need to declarate it as a global variable or give it to the sub as a parameter when it called.- You can use WriteLine <text> instead of Write <text> & vbCrLf- You missed a Trim form the ReadLine, it no cause a problem if your input file is well constructed but if there is a mistyped space or enter the script will fail.- It requires calling the Close method for the properly close the files.
What can you do now:- So at first decelerate the variables in the rigth palace and switch off the error suppression. You can use the Option Explicit statement for find undeclarated variables.- Based on the error messages you can fix the code step-by-step.- If the script works you can test it with misstyped input file, missing server etc. for add a basic error tolerance.- Keep in mind the registry provider requires admin rights on the target computer and the firewalls/routers my prevent the connection.
VBScript Variables & scopehttp://msdn.microsoft.com/en-us/library/t7zd6etz(VS.85).aspx
FileSystemObject Objecthttp://msdn.microsoft.com/en-us/library/6kxy1a51(VS.85).aspx
You can find more information in the Windows Script 5.6 Documentationhttp://www.microsoft.com/DOWNLOADS/details.asp ... laylang=en
finding out softwares
As an example of how to set up for using the registry and getting most of teh file issues in place here is a partial re-write that may help you to see how to approach scripting issues.
The following works and doesn't insert troubling code issues. If you take time to understand what is gouing on it should be very easy to modify to your final needs.
The Win32_Product class is much easier to use and works more reliably.
NOT: There is NO "On Error" statement needed.
jvierra2009-10-09 09:00:15
The following works and doesn't insert troubling code issues. If you take time to understand what is gouing on it should be very easy to modify to your final needs.
The Win32_Product class is much easier to use and works more reliably.
NOT: There is NO "On Error" statement needed.
Code: Select all
Set fso = CreateObject("Scripting.FileSystemObject")
Set FileRead = fso.openTextFile("Servers.txt")
do until FileRead.AtEndOfStream
server = FileRead.Readline()
FindKeys server, "Adobe Reader"
Loop
Function Log( msg )
WScript.Echo msg
Set logFile = fso.openTextFile("Results.csv", 8, True)
logFile.WriteLine msg
logFile.Close
End Function
Sub FindKeys(strComputer, sSoftware)
Const HKLM = &H80000002
Dim strDispName, strVer
blnFound = False
Set objReg = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv")
arrSearchKeys = Array("SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall", "SOFTWAREMicrosoftWindowsCurrentVersionUninstall")
arrSearchKeys = Array("SOFTWAREMicrosoftWindowsCurrentVersionUninstall")
For Each key in arrSearchKeys
objReg.EnumKey HKLM, key, arrSubKeys
For Each subkey In arrSubKeys
objReg.GetStringValue HKLM, key & "" & SubKey, "DisplayName", strDispName
objReg.GetStringValue HKLM, key & "" & SubKey, "DisplayVersion", strVer
If strDispName "" Then
i = InStr(UCase(strDispName), UCase(sSoftware))
If i > 0 Then ' MUST BE GREATER THAN 0
Log strComputer & "," & strDispName & "," & strVer
Exit Sub
End If
End If
Next
Next
Log strComputer & ",Not Found"
End Sub
jvierra2009-10-09 09:00:15