How do you do....it? Thread, PC's left on overnight / weekend in Technical; I run a simple AD network and am able to just run a series of .bat files from my dns ...
-
15th November 2007, 07:20 PM #16 Re: PC's left on overnight / weekend
I run a simple AD network and am able to just run a series of .bat files from my dns server via Task Scheduler.
example
shutdown -s -m \\midlab01 -t 200 -c "Nightly Shutdown in Progress."
shutdown -s -m \\midlab02 -t 200 -c "Nightly Shutdown in Progress."
shutdown -s -m \\midlab03 -t 200 -c "Nightly Shutdown in Progress."
etc etc.
If the machine is on, it pops up a windows with a countdown and a message. If the machine is off, the script delays a few seconds, then skips to the next line of the scipt.
Free and easy for my situation.
-
-
IDG Tech News
-
15th November 2007, 10:44 PM #17 Re: PC's left on overnight / weekend
I've scheduled all my machines to call a batch file from the netlogon share at 9:00pm, which in turn calls the shutdown command. It would be very easy to include a small command in the batch file which logs which machines it's turned off into a simple text file.
I added this scheduled task automatically by using the AT command in a startup script, that way we can easily change the time, or stop it being called alltogether, or change what happens by changing the batch file. It works 100% reliably, I check the rooms most mornings and never find any PCs on now.
Best bit about this solution is it's very easy, and free!
Mike.
-
-
16th November 2007, 11:48 AM #18 Re: PC's left on overnight / weekend

Originally Posted by
secman I have used the Sysinternals psshutdown program (free) and a series of batch files (never got around to sorting scripts) and a scheduler program.
We do have a couple of machines that need to be on or staff who work late so I can't have a blanket shutdown.
Ditto - its dead easy
-
-
16th November 2007, 11:54 AM #19 Re: PC's left on overnight / weekend
'deviceStatus_v2-9.vbs.
'A script to check the availability of computers specified in a file, on the network.
'Created 01/05/2007
'By Stewart Knight
'Option Explicit is used to prevent the script from running if it comes across an error.
Option Explicit
'This is where the variables are declared.
Dim objShell, objExec, strTarget, strPingResults, objFSO, objFile
Dim objCreate, strDevice, strComputer, objWMIService, colPings
Dim objPing, objResult, objEmail, objReadFile,inpAddress,inpFileName
Dim objCheckFileExists, objFileSystemObject, objMailAddress, objDictionary
Dim objPersistant, objReadAllErrors, objCompareError, objCheckErrors
Dim strCheck2, strCheck1, strCheck3, strCompare1, strCompare2, strCompare
Dim varLoop
'This is the main section of the script, where all the functions are called.
createDictionary
checkFile
checkErrors
compareLogs
mailSend
'This is where the functions are defined.
Function execPing
'This is the routine that pathpings the computers from the file strTarget.
Set objShell = CreateObject("WScript.Shell")
Set objExec = objShell.Exec("pathping " & strTarget)
strPingResults = LCase(objExec.StdOut.ReadAll)
If InStr(strPingResults, "reply from") Then
ExecPing = True
Else
ExecPing = False
End If
End Function
Function checkFile
'This checks that the file for the list of computers exists.
Set objFileSystemObject = CreateObject("Scripting.FileSystemObject")
If (objFileSystemObject.FileExists("CS.txt")) Then
objCheckFileExists = True
Else
objCheckFileExists = False
End If
'This outputs an error message if the file does not exists, then terminates the script.
On Error Resume Next
If objCheckFileExists = False Then
WScript.Echo "Unable to find file"
WScript.Quit
End If
'This collect the names of the computers from the file and uses the Function
'execPing to check if they are available.
set objFSO = CreateObject("Scripting.FileSystemObject")
set objFile = objFSO.OpenTextFile(inpFileName, 1)
set objCreate = objFSO.CreateTextFile("c:\results.txt", 2)
Do While Not objFile.AtEndOfStream
strDevice = objFile.ReadLine
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPings = objWMIService.ExecQuery _
("Select * From Win32_PingStatus where Address = '" & strDevice & "'")
If Err = 0 Then
Err.Clear
For Each objPing in colPings
If objPing.StatusCode = 0 Then
objResult = strDevice & " available." & "IP Address: " & objPing.ProtocolAddress
Else
objResult = strDevice & " not available."
End If
Next
Else
Err.Clear
If ExecPing = True Then
GetName
End If
End If
objCreate.WriteLine(objResult & ": " & Now)
Loop
objFile.Close
objCreate.Close
'Confirms that pathping has run successfully.
wscript.echo "The output has been saved into the file 'results.txt'."
End Function
Function checkErrors
'This opens a log file of all the computers that have been checked.
'It then checks to see which were unavailable, and stores that information
'in an error file and a dictionary file.
set objFSO = CreateObject("Scripting.FileSystemObject")
set objFile = objFSO.OpenTextFile("c:\results.txt", 1)
set objCreate = objFSO.CreateTextFile("c:\errors.txt", 2)
set objDictionary = objFSO.OpenTextFile("c:\Persistant.txt", 8)
Do While Not objFile.AtEndOfStream
strDevice = objFile.ReadLine
If InStr(strDevice, "not") Then objCreate.WriteLine strDevice
If InStr(strDevice, "not") Then objDictionary.WriteLine strDevice
Loop
objFile.Close
objCreate.Close
objDictionary.Close
'Confirms that the procedure has completed, and that the data has been output.
wscript.echo "The unavailable computers are listed in the file 'errors.txt.'"
End Function
Function mailSend
'This Checks that there is an email address to email the file to.
inpAddress = inputbox("Enter the email address")
Set objFileSystemObject = CreateObject("Scripting.FileSystemObject")
If inpAddress <> "" Then
objMailAddress = True
Else
objMailAddress = False
End If
'This handles the error if there is no email address.
On Error Resume Next
If objMailAddress = False Then
WScript.Echo "No email Address was entered, this log has not been emailed."
WScript.Quit
End If
'This is the email routine.
Set objEmail = CreateObject("CDO.Message")
objEmail.Subject = "Unavailable computers"
objEmail.From = "stewart.knight@appleby.cumbria.sch.uk"
objEmail.To = inpAddress
objEmail.TextBody = "The computers in the attached file were unavailable when this VB Script was run."
objEmail.AddAttachment "c:\end.txt"
objEmail.Send
'Confirms that the email has been sent.
WScript.Echo "The list of computers that are not available has been emailed to: " _
& inpAddress
End Function
Function createDictionary
'The purpose of this is to check if the dictionary file exists,
'if it does not, then it creates one.
Set objFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set objPersistant = objFSO.OpenTextFile ("c:\persistant.txt", 8)
Set objPersistant = objFSO.CreateTextFile("c:\persistant.txt",8)
objPersistant.Close
End Function
Function compareLogs
'The error log is compare to the dictionary to see if the device has failed before.
'The output is then stored in a file to be emailed to the specified address.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set strCheck1 = objFSO.OpenTextFile("c:\errors.txt")
Set strCheck2 = objFSO.OpenTextFile("c:\persistant.txt")
Set strCheck3 = objFSO.CreateTextFile("c:\end.txt",2)
Do While Not strCheck1.atEndOfStream
strCompare1 = strCheck1.ReadLine
Set strCheck2 = objFSO.OpenTextFile("c:\persistant.txt")
Do While Not strCheck2.atEndOfStream
strCompare2 = strCheck2.ReadLine
If inStr(strCompare1,10) = inStr(strCompare2,10) Then strCheck3.WriteLine strCompare2 _
& " Failed again at " & Now
Loop
strCheck2.Close
Loop
strCheck1.Close
strCheck3.Close
End Function
'End of Script
-
SHARE:
Similar Threads
-
By contink in forum Hardware
Replies: 2
Last Post: 10th September 2007, 08:36 AM
-
By russdev in forum General Chat
Replies: 10
Last Post: 7th October 2006, 09:39 PM
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules