none
vbscript comparing file version RRS feed

  • Question

  • I've written the following script to first determine an OS based on a string then determine if a file version is compliant by being equal to or greater than the version returned (with a string wtest set to test the logic):

    On Error Resume Next Const ForReading = 1 Const ForWriting = 2 Const TriStateUseDefault = -2 strComputer = "." strReport = "report.csv" w2003 = "5.2.3790.6021" w2008 = "6.0.6002.19743" w2008r2 = "6.1.7601.23689" w2012 = "6.2.9200.22099" w2012r2 = "6.3.9600.18604" w2016 = "10.0.14393.953" wtest = "100000" oswin7 = "Windows 7" os2008r2 = "2008 R2" os2012r2 = "Microsoft Windows Server 2012" os2012r2 = "Server 2012 R2" os2016 = "2016" Set RE = New RegExp RE.IgnoreCase = True Set objFSO = CreateObject("Scripting.FileSystemObject") Set objReport = objFSO.OpenTextFile(strReport, ForWriting, True) objReport.WriteLine "Hostname,Domain,File Verion,Compliance,OS Version" Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colFiles = objWMIService.ExecQuery ("Select Version from CIM_Datafile Where Name = 'c:\\windows\\system32\\drivers\\srv.sys'") For Each objFile in colFiles Set oss = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem") For Each os in oss Set wshShell = CreateObject( "WScript.Shell" ) strUserDomain = wshShell.ExpandEnvironmentStrings( "%USERDOMAIN%" ) If ((InStr( 1, os.Caption, oswin7, vbTextCompare, 1)) And (objFile.Version >= wtest)) then MsgBox "Compliant" Elseif ((InStr( 1, os.Caption, oswin7, vbTextCompare, 1)) And (objFile.Version >= wtest)) then MsgBox = "Not Compliant" End if

    Next Next objReport.Close MsgBox "Process Completed", vbOKOnly, "Status"

    However I get compliant every time.

    What am I missing?


    Wednesday, May 24, 2017 1:32 AM

Answers

All replies