Boston2012 Posted November 5, 2012 Share Posted November 5, 2012 Hello, I'm trying to edit my script to add another field in the.CSV file to indicate if OS is Windows 2000 or Windows 2008. Win I run this on either a 2K or 08 system the .CSV file is showing "Windows_NT" , can you tell me where I'm going wrong with this. Copy of scrip is below:'Option ExplicitOn Error Resume NextDim strNewContents, strLine, objFile,SuccessFile,strSuccessFlag,SuccessCode,strCritcalFlag,CriticalFileDim objShell,strOSSet objFSO = CreateObject("Scripting.FileSystemObject")Set objNetwork = CreateObject("WScript.Network")Set objShell = CreateObject("WScript.Shell")' ConstantsConst ForReading = 1Const ForWriting = 2Const ForAppending = 8strThisComputer = objNetwork.ComputerNamestrFileOutput = "C:\TJXLogs\" & KMSPing & "KMSPing.csv"strSuccessFlag = "C:\TJXLogs\Success.flag"strOS = objShell.ExpandEnvironmentStrings("%OS%")If objFSO.FileExists(strFileOutput) Then Set objOutputFile = objFSO.OpenTextFile (strFileOutput, ForWriting)Else Set objOutputFile = objFSO.CreateTextFile(strFileOutput, True)End IfIf Err <> 0 Then Wscript.Echo "Unable to open " & strFileOutput & " for output." WScript.QuitEnd IfIf objFSO.FileExists(strFileOutput) Then Set objOutputFile = objFSO.OpenTextFile (strFileOutput, ForWriting)Else Set objOutputFile = objFSO.CreateTextFile(strFileOutput, False)End IfstrTarget = "172.24.72.155" If Ping(strTarget) = True Then strResult = "True" set objsuccessflag = objFSO.CreateTextFile(strSuccessFlag, False)Else strResult = "False"End IfstrFileOutput = "C:\TJXLogs\" & KMSPing & "KMSPing.csv"Set objFSO = CreateObject("Scripting.FileSystemObject")objOutputFile.Write """" & strThisComputer & """,""" & StrOS & """,""" & strResult & """,""" & Now & """"objOutputFile.CloseFunction Ping(strComputer) Dim objShell, boolCode Set objShell = CreateObject("WScript.Shell") boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True) If boolCode = 0 Then Ping = True Else Ping = False End IfEnd Function Link to comment Share on other sites More sharing options...
allen2 Posted November 5, 2012 Share Posted November 5, 2012 Replace this line:strOS = objShell.ExpandEnvironmentStrings("%OS%")With those:for each objOS in GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem")strOS=objOS.Captionnext Link to comment Share on other sites More sharing options...
Boston2012 Posted November 6, 2012 Author Share Posted November 6, 2012 Thanks, that did work. Anyway to abbreviate the output to show just:Windows 2000Windows 2008 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now