RE: Auto shutdown of workstations



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



Relevant Pages

  • Re: Install printers to groups of users or computers by using Group Policy
    ... I have 4 remote offices connecting to the SBS 2003 server and I ... This is the script gotten from TechNet that I am ... Based on my research, in SBS 2003 environment, the client printer is ... computers running Windows XP pro or Windows 2000 Pro. ...
    (microsoft.public.windows.server.sbs)
  • Re: Problems with Computers discovered
    ... MVP Windows Server System - SMS ... I saw something very weird today with my SMS, I have almost 2500 computers ... the client of sms i'm using a script, but, i only assigned this script to a ... advanced client. ...
    (microsoft.public.sms.admin)
  • Re: Problems with Computers discovered
    ... > I saw something very weird today with my SMS, I have almost 2500 computers ... > script to a very small group in my active directory called DG, ... > computers have the advanced client. ... > ** at this level i put my logon script to install the client. ...
    (microsoft.public.sms.admin)
  • Re: Permission denied only when 2 computers are used
    ... situation as all the client are either Windows 2000 or better; ... both computers need WMI installed. ... >> When I run this script using 1 remote computer name, ...
    (microsoft.public.scripting.vbscript)
  • Re: Finding users in local admin groups
    ... > Here is a vbscript that you can run against a remote computer that moves ... > *local* users except 'Administrator) from the Administrators group to the ... You should also add to the script logging to a file of the ... > you moved on what computers. ...
    (microsoft.public.win2000.security)