Boston2012
Technical User
How do I update my .CSV file in my VBS script to include a new line? Were trying to merge several .CSV files into one and it's not working correctly. Copy of script i'm using 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("Win32_OperatingSystem")
'Determine Operating System
for each objOS in GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem")
strOS=objOS.Caption
next
If LCase(strOS) = RTrim(LCase("Microsoft Windows 2000 Server")) Then
strOS = "Windows 2000"
ElseIf LCase(strOS) = Rtrim(LCase("Microsoft Windows Server 2008 Standard")) Then
strOS = "Windows 2008"
Else
strOS = "Windows 2008"
End If
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
'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("Win32_OperatingSystem")
'Determine Operating System
for each objOS in GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem")
strOS=objOS.Caption
next
If LCase(strOS) = RTrim(LCase("Microsoft Windows 2000 Server")) Then
strOS = "Windows 2000"
ElseIf LCase(strOS) = Rtrim(LCase("Microsoft Windows Server 2008 Standard")) Then
strOS = "Windows 2008"
Else
strOS = "Windows 2008"
End If
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