I am trying to create a Script to stop and start a Service...for a list of machines
Below is my code,...
I kept on getting an issue with The Function Line????
========
Const ForReading = 1
dim objFSO, strFile, strFilePath, OFile, oFile2, strPCNum, strOutputFile, strRemoteFile, strFileVersion, strOutText
Set objFSO = CreateObject("Scripting.FileSystemObject")
set objShell = CreateObject("WScript.Shell")
strInputFile = InputBox("Enter the file path to the file containing the list of PCs", "Enter the file path")
if strInputFile = "" then
wscript.echo "No file path supplied. Quitting Program"
wscript.quit
end if
strOutputFile = InputBox("Enter the file path to write the results to", "Enter the file path")
if strOutPutFile = "" then
wscript.echo "No file path supplied. Quitting Program"
wscript.quit
end if
set oFile = objFSO.OpenTextFile(strInputFile,1)
set oFile2 = objFSO.OpenTextFile(strOutputFile,8,True)
do while not oFile.atendofstream
strPCNum=oFile.readline
if Ping(strPCNum) = False Then
strOutText = strPCNum + vbTab + "Off LINe"
oFile2.WriteLine(strOutText)
Else
Const SERVNAME = "schedule"
Const WAITTIME = 10000
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strPCNum & "\root\cimv2")
Set colServices = objWMIService.ExecQuery ("SELECT * FROM win32_Service")
For Each objService in colServices
'WScript.Echo objService.Name 'Uncomment to list all service names on the machine
If objService.Name = SERVNAME Then
errReturnCode = objService.StopService()
WScript.Sleep WAITTIME
errReturnCode = objService.StartService()
strOutText = strPCNum + vbTab + "Restarted Service"
oFile2.WriteLine(strOutText)
End If
Next
Function Ping(PC)
Set objWshScriptExec = objShell.Exec("ping.exe -n 1 " & PC)
Set objStdOut = objWshScriptExec.StdOut
awake=False
Do Until objStdOut.AtEndOfStream
strLine = objStdOut.ReadLine
awake = awake Or InStr(LCase(strLine), "bytes=") > 0
Loop
Ping = awake
End Function
=========
PLease help
Below is my code,...
I kept on getting an issue with The Function Line????
========
Const ForReading = 1
dim objFSO, strFile, strFilePath, OFile, oFile2, strPCNum, strOutputFile, strRemoteFile, strFileVersion, strOutText
Set objFSO = CreateObject("Scripting.FileSystemObject")
set objShell = CreateObject("WScript.Shell")
strInputFile = InputBox("Enter the file path to the file containing the list of PCs", "Enter the file path")
if strInputFile = "" then
wscript.echo "No file path supplied. Quitting Program"
wscript.quit
end if
strOutputFile = InputBox("Enter the file path to write the results to", "Enter the file path")
if strOutPutFile = "" then
wscript.echo "No file path supplied. Quitting Program"
wscript.quit
end if
set oFile = objFSO.OpenTextFile(strInputFile,1)
set oFile2 = objFSO.OpenTextFile(strOutputFile,8,True)
do while not oFile.atendofstream
strPCNum=oFile.readline
if Ping(strPCNum) = False Then
strOutText = strPCNum + vbTab + "Off LINe"
oFile2.WriteLine(strOutText)
Else
Const SERVNAME = "schedule"
Const WAITTIME = 10000
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strPCNum & "\root\cimv2")
Set colServices = objWMIService.ExecQuery ("SELECT * FROM win32_Service")
For Each objService in colServices
'WScript.Echo objService.Name 'Uncomment to list all service names on the machine
If objService.Name = SERVNAME Then
errReturnCode = objService.StopService()
WScript.Sleep WAITTIME
errReturnCode = objService.StartService()
strOutText = strPCNum + vbTab + "Restarted Service"
oFile2.WriteLine(strOutText)
End If
Next
Function Ping(PC)
Set objWshScriptExec = objShell.Exec("ping.exe -n 1 " & PC)
Set objStdOut = objWshScriptExec.StdOut
awake=False
Do Until objStdOut.AtEndOfStream
strLine = objStdOut.ReadLine
awake = awake Or InStr(LCase(strLine), "bytes=") > 0
Loop
Ping = awake
End Function
=========
PLease help