MSFN Forum: VB Script - MSFN Forum

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

VB Script Rate Topic: -----

#1 User is offline   Boston2012 

  • Group: Members
  • Posts: 8
  • Joined: 26-October 12
  • OS:Server 2008 x86
  • Country: Country Flag

Posted 05 November 2012 - 01:40 PM

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 Explicit
On Error Resume Next

Dim strNewContents, strLine, objFile,SuccessFile,strSuccessFlag,SuccessCode,strCritcalFlag,CriticalFile
Dim objShell,strOS
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network")
Set objShell = CreateObject("WScript.Shell")

' Constants
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

strThisComputer = objNetwork.ComputerName
strFileOutput = "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 If

If Err <> 0 Then
Wscript.Echo "Unable to open " & strFileOutput & " for output."
WScript.Quit
End If

If objFSO.FileExists(strFileOutput) Then
Set objOutputFile = objFSO.OpenTextFile (strFileOutput, ForWriting)
Else
Set objOutputFile = objFSO.CreateTextFile(strFileOutput, False)
End If


strTarget = "172.24.72.155"
If Ping(strTarget) = True Then
strResult = "True"
set objsuccessflag = objFSO.CreateTextFile(strSuccessFlag, False)
Else
strResult = "False"
End If

strFileOutput = "C:\TJXLogs\" & KMSPing & "KMSPing.csv"



Set objFSO = CreateObject("Scripting.FileSystemObject")
objOutputFile.Write """" & strThisComputer & """,""" & StrOS & """,""" & strResult & """,""" & Now & """"
objOutputFile.Close

Function 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 If

End Function


#2 User is offline   allen2 

  • Not really Newbie
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 1,736
  • Joined: 13-January 06

Posted 05 November 2012 - 02:22 PM

Replace this line:
strOS = objShell.ExpandEnvironmentStrings("%OS%")

With those:
for each objOS in GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem")
strOS=objOS.Caption
next




#3 User is offline   Boston2012 

  • Group: Members
  • Posts: 8
  • Joined: 26-October 12
  • OS:Server 2008 x86
  • Country: Country Flag

Posted 05 November 2012 - 09:52 PM

Thanks, that did work. Anyway to abbreviate the output to show just:

Windows 2000
Windows 2008

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy