Announcement

Collapse
No announcement yet.

Automatic Shutdown

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Automatic Shutdown

    Dear All,

    I am currently setting up a lab to administer, and would like to make all the lab computers shutdown automatically at 06:00 pm for example. Those computers are joined to a domain, any suggestions behind that?

    A script or a batched script will do that?

    Hope someone can help in that.
    Best regards,
    Mostafa Itani

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

  • #2
    Re: Automatic Shutdown

    Wow, dude, there are so many options here...
    I did a quick search: http://www.google.com/search?q=schedule+shutdown+xp

    But you can always go for the easy way (in my opinion, it's a great tool): Microsoft-SysInternal's PSShutdown.
    Good luck.

    Sorin Solomon


    In order to succeed, your desire for success should be greater than your fear of failure.
    -

    Comment


    • #3
      Re: Automatic Shutdown

      Been there, done that and even got the T-shirt (But don't ask for proof)

      http://forums.petri.com/showthread.p...hutdown+script

      Michael
      Michael Armstrong
      www.m80arm.co.uk
      MCITP: EA, MCTS, MCSE 2003, MCSA 2003: Messaging, CCA, VCP 3.5, 4, 5, VCAP5-DCD, VCAP5-DCA, ITIL, MCP, PGP Certified Technician

      ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

      Comment


      • #4
        Re: Automatic Shutdown

        maybe that's replies are the best, but i just got another idea but that's for you to research not to just apply as it's not tested

        make a bath file with
        shutdown -s -t 0

        and save it in the shared space, like the netlogon folder

        and use a start up script with the AT command
        http://support.microsoft.com/kb/313565
        that scheduales that batch on the shared to run dailly at the required time and it will be enrolled after a while to all users in their scheduled tasks and then you can remove the start up script , you can cancel it later if you wish by means of AT command still, the art will be with using the AT command

        research for the AT command parameters and try to do it on the lab and verify it and it will be the easiest solution

        Comment


        • #5
          Re: Automatic Shutdown

          I thought I'd add my two cents.

          Here's script that will shutdown all the client computers (XP and 2k Pro) in the domain. You can run this with Domain Admin privileges from any computer that has the tools installed (the shutdown command is on XP and later systems).

          If you want it to shutdown servers, including the computer it is run from, remove the text highlighted in red.

          I put in the option of using either shutdown.exe or psshutdown.exe. Both have been commented out (in blue) so you need to remove the single quote from the beginning of the line for the method you want to use.


          Code:
          On Error Resume Next
          
          '* Enter the DN of the container you want to base your 
          '* search in excluding the domain name (dc=domain,dc=com)
          '* between the double quotes below. If you want it to
          '* search the root leave it blank.
          
          strContainer = "" 
          
          Set objRootDSE = GetObject("LDAP://rootDSE")
          
          If strContainer = "" Then
              strADsPath = objRootDSE.Get("defaultNamingContext")
          Else
              strADsPath = strContainer & "," & objRootDSE.Get("defaultNamingContext")
          End If
          
          Set objConnection = CreateObject("ADODB.Connection")
          objConnection.Open "Provider=ADsDSOObject;"
          
          Set objCommand = CreateObject("ADODB.Command")
          objCommand.ActiveConnection = objConnection
          
          
          '--- change the DN to where you want to start your search ---
          objCommand.CommandText = _
              "<LDAP://" & strADsPath & ">;" & _
                  "(&(objectCategory=computer)(|(operatingSystem=Windows XP*)(operatingSystem=Windows 2000 P*)))" & _
                  ";name;subtree"
           
          Set objRecordSet = objCommand.Execute
          
          While Not objRecordSet.EOF
          
              ShutdownComputer objRecordSet.Fields("Name")
              objRecordSet.MoveNext
          
          Wend
          
          objConnection.Close
          
          
          Sub ShutdownComputer(strComputer)
          
              set objShell = CreateObject("WScript.Shell") 
          
          '----Below, remove the single quote -> ' <- from in front of the tool you want to use----
          '    objShell.Run "shutdown -s -t 0 -f -m \\" & strComputer
          '    objShell.Run "psshutdown.exe \\" & strComputer & " -k -f -t 90"
          
           
          
          End Sub
          EDIT - A few of the advantages of shutting down all the from a single location is:
          - there's only one scheduled task to manage
          - changes only need to be made to one script
          - there's no deployment necessary for the psshutdown or any other tool or script (TBH, the deployment of psshutdown is ridiculously simple)

          And I'm sure you can think of more advantages.

          EDIT 2 - BTW, if you don't want to shutdown all the computers then there's ways to narrow the search to certain OUs or groups or whatever you like. Just let us know the requirements.
          Last edited by JeremyW; 8th August 2007, 03:34.
          Regards,
          Jeremy

          Network Consultant/Engineer
          Baltimore - Washington area and beyond
          www.gma-cpa.com

          Comment


          • #6
            Re: Automatic Shutdown

            Hello Jermey,

            Thank you for the post, so what I understand from you I have to do the following:

            Sorry I have been dealing with Linux systems for the last six months and seems I missed many things in Windows.

            I will post what I could do and please correct me:

            Code:
            On Error Resume Next
            
            '* Enter the DN of the container you want to base your 
            '* search in excluding the domain name (dc=domain,dc=com)
            '* between the double quotes below. If you want it to
            '* search the root leave it blank.
            '* In my case I have the following domain acc.aub.edu.lb and have the following OUS ACC Lab, and inside it a sub OU Lab Computers
            acc.aub.edu.lb
            ACC Lab
            Lab Computers
            strContainer = "" Set objRootDSE = GetObject("LDAP://rootDSE") If strContainer = "" Then strADsPath = objRootDSE.Get("defaultNamingContext") Else strADsPath = strContainer & "," & objRootDSE.Get("defaultNamingContext") End If Set objConnection = CreateObject("ADODB.Connection") objConnection.Open "Provider=ADsDSOObject;" Set objCommand = CreateObject("ADODB.Command") objCommand.ActiveConnection = objConnection '--- change the DN to where you want to start your search --- objCommand.CommandText = _ "<LDAP://" & strADsPath & ">;" & _ "(&(objectCategory=computer)(|(operatingSystem=Windows XP*)(operatingSystem=Windows 2000 P*)))" & _ ";name;subtree" Set objRecordSet = objCommand.Execute While Not objRecordSet.EOF ShutdownComputer objRecordSet.Fields("Name") objRecordSet.MoveNext Wend objConnection.Close Sub ShutdownComputer(strComputer) set objShell = CreateObject("WScript.Shell") '----Below, remove the single quote -> ' <- from in front of the tool you want to use---- objShell.Run "shutdown -s -t 0 -f -m \\" & strComputer ' objShell.Run "psshutdown.exe \\" & strComputer & " -k -f -t 90" End Sub
            I am correct with what I am doing?
            Sorry but have not dealt with Windows systems for almost six months, and seems I am loosing all my talents.
            Best regards,
            Mostafa Itani

            ** Remember to give credit where credit is due and leave reputation points where appropriate **

            Comment


            • #7
              Re: Automatic Shutdown

              Not a problem.

              It's very close but not quite right.

              Below the script is modified to shutdown computers only in the Lab Computers OU.

              Code:
              On Error Resume Next
              
              '* Enter the DN of the container you want to base your 
              '* search in excluding the domain name (dc=domain,dc=com)
              '* between the double quotes below. If you want it to
              '* search the root, leave it blank.
              '* In my case I have the following domain acc.aub.edu.lb and have the following OUS ACC Lab, and inside it a sub OU Lab Computers
              
              strContainer = "ou=Lab Computers,ou=ACC Lab"
              
              Set objRootDSE = GetObject("LDAP://rootDSE")
              
              If strContainer = "" Then
                  strADsPath = objRootDSE.Get("defaultNamingContext")
              Else
                  strADsPath = strContainer & "," & objRootDSE.Get("defaultNamingContext")
              End If
              
              Set objConnection = CreateObject("ADODB.Connection")
              objConnection.Open "Provider=ADsDSOObject;"
              
              Set objCommand = CreateObject("ADODB.Command")
              objCommand.ActiveConnection = objConnection
              
              
              objCommand.CommandText = _
                  "<LDAP://" & strADsPath & ">;" & _
                      "(objectCategory=computer)" & _
                      ";name"
               
              Set objRecordSet = objCommand.Execute
              
              While Not objRecordSet.EOF
              
                  ShutdownComputer objRecordSet.Fields("Name")
                  objRecordSet.MoveNext
              
              Wend
              
              objConnection.Close
              
              
              Sub ShutdownComputer(strComputer)
              
                  set objShell = CreateObject("WScript.Shell") 
              
              '----Below, remove the single quote -> ' <- from in front of the tool you want to use----
                  objShell.Run "shutdown -s -t 90 -f -m \\" & strComputer
              '    objShell.Run "psshutdown.exe \\" & strComputer & " -k -f -t 90"
              
               
              
              End Sub
              Also note that I took out the filter to return only client machines. So the script will now shutdown any Windows machine (servers et al) in that OU.
              Last edited by JeremyW; 8th August 2007, 14:13. Reason: left a semicolon in by accident
              Regards,
              Jeremy

              Network Consultant/Engineer
              Baltimore - Washington area and beyond
              www.gma-cpa.com

              Comment


              • #8
                Re: Automatic Shutdown

                nice script!

                It can save time to perform also a 'ping test' first to see if the computer is on-line before psShutdown spends even more time trying to connect to a computer that is off-line.

                Code:
                'code snippet 
                '
                '
                strComputer = "test"
                
                If IsConnectable(strComputer) then
                msgbox "you can shutdown this remote computer"
                End If
                
                
                Function IsConnectable(strComputer)
                 'This routine works only! for Windows XP and newer)
                 'For older versions of windows: http://groups.google.co.uk/group/microsoft.public.scripting.vbscript/msg/fd925a383d88045d
                  Set colItems = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
                  ("SELECT StatusCode FROM Win32_PingStatus where address = '" & strComputer & "'")
                  For Each objItem in colItems
                    if objItem.StatusCode = 0 Then
                    	IsConnectable = True
                    Else
                    	IsConnectable = False 
                    End if
                  Next
                  IsConnectable = IsConnectable
                End Function


                In stead of using a command-line to shutdown the remote computer (psShutdown.exe ...), you can also use the Win32Shutdown Method of the Win32_OperatingSystem Class.
                example: http://forums.petri.com/showthread.p...6298#post56298 (<-- a bit dirty script, no T-shirt in it for me).

                \Rems
                Last edited by Rems; 8th August 2007, 19:15.

                This posting is provided "AS IS" with no warranties, and confers no rights.

                __________________

                ** Remember to give credit where credit's due **
                and leave Reputation Points for meaningful posts

                Comment


                • #9
                  Re: Automatic Shutdown

                  Thank you for the update guys.

                  I have been thinking while having a cup of tea today afternoon, and got the following:

                  Will create a network share that will contain psshutdown and another batch file, and will link this to a computer start up policy, that way every computer in the OU even the newly added ones will get a copy of psshutdown and copy it to the local computer in addition to a file that will start the psshutdown with the arguments needed.

                  Another script that will add the batch file to the scheduler. That way every computer will add a scheduled task to run at time for example 06:00 pm.

                  What you think guys?
                  Best regards,
                  Mostafa Itani

                  ** Remember to give credit where credit is due and leave reputation points where appropriate **

                  Comment


                  • #10
                    Re: Automatic Shutdown

                    Originally posted by sanvour View Post
                    What you think guys?
                    Well it will work... but wouldn't using just one script, tool, and computer to shutdown all the necessary computers be less effort then configuring multiple scripts, copying files, and managing multiple scheduled tasks? Granted, managing tools and tasks can be done through scripts so it's really just a matter of maintaining a few scripts (and GPO)

                    But either way will work.

                    PS - we can help you incorporate Rems' excellent suggestions if you're not sure how to do it.
                    Regards,
                    Jeremy

                    Network Consultant/Engineer
                    Baltimore - Washington area and beyond
                    www.gma-cpa.com

                    Comment


                    • #11
                      Re: Automatic Shutdown

                      Dear Jermey,

                      I will do some testings now, to see that, but I think Rem's solution is excellent. It is bettern integrating it for others also.
                      Best regards,
                      Mostafa Itani

                      ** Remember to give credit where credit is due and leave reputation points where appropriate **

                      Comment

                      Working...
                      X