RE: Auto shutdown of workstations
- From: Djmc26 <Djmc26@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 19 Jan 2006 01:04:03 -0800
Hi Stewy
would it be possible to use in the texty file the * wildcard?
Like for example
AULAP8-*.*
since all my pc are AULAP8-pc1, pc2, pc3, blah blah blah
Thanks
i.
"Stewy" wrote:
> I created a script at my last job that shutdown certain computers at a
> specific time. The script would read a text file (which contained computer
> names) and go along and shut them down. At the end it would email a log file
> to you stating which computers where left on. The script must be fired by
> having the argument "scheduled" otherwise it won't run. When testing we
> accidently shut down all the computers during work hours. As for time wise we
> set it up as a Scheduled task for a certain time. It was safer doing it this
> way.
>
> This script is as is and you may need to modify it for your needs...
>
> '=====================================================
> ' VBScript Source File -- Created with XLnow OnScript
> '
> ' AUTHOR: Stewart Brown
> ' DATE: 17/06/2005
> ' COMMENT: This reads a textfile of computers and shuts them down.
> ' If anything is left open and unsaved then tough, it will be
> ' forced to shutdown.
> ' This has now been dumbed down for Win 2000 and below...
> '=====================================================
>
> ' Before we start lets check to see if we should be running this script
> if WScript.arguments.length > 0 then
> Select Case WScript.arguments.item(0)
> Case "scheduled"
> ' We do nothing as we are suppose to run this script.
> Case Else
> WScript.Echo "By you running this script you are now in the process of
> shutting down all computers across the network. Have a nice day :)"
> WScript.Echo "Only kidding, this script has been stopped because you ran
> it incorrectly."
> WScript.Quit
> End Select
> else
> WScript.Echo "By you running this script you are now in the process of
> shutting down all computers across the network. Have a nice day :)"
> WScript.Echo "Only kidding, this script has been stopped because you ran it
> incorrectly."
> WScript.Quit
>
> end if
>
> ' Lets force our error trapping
> On Error Resume Next
>
> ' Declare Variables time
> Dim oFSO, oTS, strComputer, colPings
> Dim sUser, sPassword
> Dim objEmail, strAttachmentFile, objFSO, objTextFile
>
> ' Lets set remote credentials
> sUser = "## Need Admin Username ##"
> sPassword = "## Need Admin Password ##"
>
> ' Settings for the email
> Set objEmail = CreateObject("CDO.Message")
> objEmail.From = "## Insert From email address ##"
> objEmail.To = "## Insert To email address ##"
> objEmail.CC = "## Insert CC email address if required. If not then comment
> this line out ##"
> objEmail.Subject = "Shutdown Report for " & date() & "."
>
> ' Set the log file
> strAttachmentFile = "## Log file to save results
> c:\misc\remoteshutdown\ShutDownLog.txt ##"
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objTextFile = objFSO.CreateTextFile (strAttachmentFile, true)
> objTextFile.Writeline ("Start time: " & time())
>
> ' Open list of client names
> Set oFSO = CreateObject("Scripting.FileSystemObject")
> Set oTS = oFSO.OpenTextFile("## Clients text file listing computer names
> c:\misc\remoteshutdown\clients.txt##")
>
> ' Lets create our loop to read each line of the text file
> Do Until oTS.AtEndOfStream
>
> ' Lets get the next client name
> strComputer = oTS.ReadLine
>
> ' Lets ping
> Set objShell = CreateObject("WScript.Shell")
> Set objScriptExec = objShell.Exec( "ping -n 2 -w 1000 " & strComputer)
> strPingResults = LCase(objScriptExec.StdOut.ReadAll)
>
> ' Lets work out the results
> If InStr(strPingResults, "reply from") Then
> ' Lets connect to the computer
> Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
> Set objSWbemServices = objSWbemLocator.ConnectServer (strComputer,
> "root\cimv2", sUser, sPassword)
> If err.number <> 0 then
> ' For testing purposes uncomment the line below
> ' Wscript.Echo strComputer & " has confused the script or won't allow
> remote connections"
> objTextFile.Writeline (strComputer & " has confused the script or won't
> allow remote connections.")
> End if
> ' Lets issue a shutdown to windows
> ' 4 = force logoff
> ' 5 = force shutdown
> ' 6 = force reboot
> ' 12 = force power off
>
> Set oWindows = objSWbemServices.ExecQuery("Select " & "Name From
> Win32_OperatingSystem")
> For Each oSys In oWindows
> oSys.Win32ShutDown(5)
> Next
>
> objTextFile.Writeline (strComputer & " HAS BEEN TURNED OFF.")
> ' For testing purposes uncomment the line below
> ' Wscript.Echo strComputer & " Computer responded and now turned off."
> else
> ' For testing purposes uncomment the line below
> ' WScript.Echo strComputer & " Computer did not respond."
> objTextFile.Writeline (strComputer & " is already off.")
> End If
>
> ' Lets get our new computer name
> Loop
>
> ' Lets close the text file
> oTS.Close
> objTextFile.Writeline ("Finish time: " & time())
> objTextFile.Close
>
> ' Lets send the email
> objEmail.AddAttachment(strAttachmentFile)
> objEmail.Configuration.Fields.Item
> ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
> objEmail.Configuration.Fields.Item
> ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "## Insert
> SMTP address ##"
> objEmail.Configuration.Fields.Item
> ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
> objEmail.Configuration.Fields.Update
> objEmail.Send
>
>
> ' =====================================================
>
> In the text file with the computers names would something like;
> M0001
> M0002
> M0003...
> etc etc
>
> Have Fun...
>
> Stewy
>
>
>
> "Just Guessing" wrote:
>
> > I have a Windows SBS 2003 server. I have about fifty workstations - most are
> > Windows 2000 Pro - a handful of Windows XP and a couple of Windows 98 SE. I
> > would like to forcibly and automatically shut down most workstations in the
> > evening. User have a tendency to leave their computers on and logged in. I
> > think forcibly shutting down workstations left on from the server is the way
> > to handle this.
> > I know about shutdown.exe, but how would this be set up on the server?
> > Thanks!
> >
.
- Follow-Ups:
- RE: Auto shutdown of workstations
- From: Stewy
- Re: Auto shutdown of workstations
- From: Evan
- RE: Auto shutdown of workstations
- References:
- RE: Auto shutdown of workstations
- From: Stewy
- RE: Auto shutdown of workstations
- Prev by Date: Re: [MSH] MSH Not So Great For Interactive Users
- Next by Date: Re: Auto shutdown of workstations
- Previous by thread: RE: Auto shutdown of workstations
- Next by thread: Re: Auto shutdown of workstations
- Index(es):
Relevant Pages
|