+ Post New Thread
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
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 ...
  1. #16
    jmair's Avatar
    Join Date
    Aug 2007
    Thank Post
    Thanked 9 Times in 9 Posts
    Rep Power

    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.

    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.

  2. #17

    maniac's Avatar
    Join Date
    Feb 2007
    Thank Post
    Thanked 432 Times in 312 Posts
    Rep Power

    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!


  3. #18

    SpuffMonkey's Avatar
    Join Date
    Jul 2005
    Thank Post
    Thanked 285 Times in 191 Posts
    Rep Power

    Re: PC's left on overnight / weekend

    Quote 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

  4. #19
    StewartKnight's Avatar
    Join Date
    Jun 2005
    Thank Post
    Thanked 27 Times in 21 Posts
    Rep Power

    Re: PC's left on overnight / weekend

    '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.


    '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
    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
    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"
    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
    For Each objPing in colPings
    If objPing.StatusCode = 0 Then
    objResult = strDevice & " available." & "IP Address: " & objPing.ProtocolAddress
    objResult = strDevice & " not available."
    End If


    If ExecPing = True Then
    End If
    End If

    objCreate.WriteLine(objResult & ": " & Now)



    '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



    '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
    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."
    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"

    '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)


    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


    End Function

    'End of Script

+ Post New Thread
Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 2
    Last Post: 10th September 2007, 09:36 AM
  2. This weekend i Will Be... at Leamington Spa
    By russdev in forum General Chat
    Replies: 10
    Last Post: 7th October 2006, 10: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