finding out softwares

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
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.
This topic is 14 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
superfly12
Posts: 133
Last visit: Sun Nov 02, 2014 4:37 pm

finding out softwares

Post by superfly12 »

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...."
User avatar
superfly12
Posts: 133
Last visit: Sun Nov 02, 2014 4:37 pm

finding out softwares

Post by superfly12 »

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...."
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

finding out softwares

Post by jvierra »

This is the correct syntax.

Select * from Win32_Product where name LIKE '%Mozilla%



Select * from Win32_Product where name = 'soft1' OR name = 'soft2'
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

finding out softwares

Post by jvierra »

What is you OS?

This will not work on Windows 2003, WS2000 ro W98 etc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

finding out softwares

Post by jvierra »

It will work on XP SP2

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.

User avatar
rasimmer
Posts: 182
Last visit: Fri Apr 25, 2014 7:00 am

finding out softwares

Post by rasimmer »

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
	
User avatar
rasimmer
Posts: 182
Last visit: Fri Apr 25, 2014 7:00 am

finding out softwares

Post by rasimmer »

If (strVer <> "") And (InStr(UCase(strDispName), "ADOBE")) Then WScript.Echo strDispName & ";" & strVer
User avatar
rasimmer
Posts: 182
Last visit: Fri Apr 25, 2014 7:00 am

finding out softwares

Post by rasimmer »

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
	
User avatar
Gyorgy Nemesmagasi
Posts: 50
Last visit: Wed Mar 16, 2022 12:58 pm

finding out softwares

Post by Gyorgy Nemesmagasi »

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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

finding out softwares

Post by jvierra »

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.

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
This topic is 14 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked