+ Post New Thread
Results 1 to 13 of 13
Scripts Thread, Shutdown Schedule in Coding and Web Development; If anyone is interested i created this vbs and batch file to create a schedule task that will run each ...
  1. #1
    tomscaper's Avatar
    Join Date
    Jul 2006
    Posts
    814
    Thank Post
    118
    Thanked 29 Times in 15 Posts
    Rep Power
    22

    Shutdown Schedule

    If anyone is interested i created this vbs and batch file to create a schedule task that will run each night, as the files get copied to the pc on start up, if the network were to go down they would still be able to shut down.

    The script consists of a vbs that runs on computer start up.

    Code:
    Option Explicit
    Dim sUserName, sLogonserver, oShell, oNetwork, WshShell
    Dim sPath1, sPath2, sPath3, sPath4, objFSO, sFavPath, objFolder, objShell
    
    Set WshShell = CreateObject("WScript.Shell")
    Set oShell = CreateObject("Wscript.shell")
    Set oNetwork = WScript.Createobject("Wscript.Network")
    
    sPath1 = "\\server\batch file location\"
    sPath2 = "C:\Program Files\"
    sPath3 = "Shutdown\"
    sPath4 = "shutdown.bat"
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    On Error Resume Next
    
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    'This Part Checks to See if the Shutdown Folder is present and creates.
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    
    If objFSO.FolderExists(sPath2 & sPath3) Then
        Set objFolder = objFSO.GetFolder(sPath2 & sPath3)
    	'msgbox("Folder Exists")
    Else
        Set objShell = CreateObject("Shell.Application")
    	Set objFolder = objShell.NameSpace(sPath2) 
    	objFolder.NewFolder "Shutdown"
    	'msgbox("Folder Created")
    End If
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    'This Part Copies the shutdown batch file
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    
    If objFSO.FileExists(sPath2 & sPath3 & sPath4) Then
    objFSO.DeleteFile(sPath2 & sPath3 & sPath4)
    objFSO.CopyFile sPath1 & sPath4 , sPath2 & sPath3
    'msgbox("File Exists, Deleted & Copied")
    else
    objFSO.CopyFile sPath1 & sPath4 , sPath2 & sPath3
    'msgbox(" File Copied")
    set objFSO = nothing
    
    End If
    
    'msgbox("End")
    
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    'This Part Copies the shutdown batch file
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    
    WshShell.Run "C:\windows\system32\schtasks.exe /Delete /TN * /F"
    
    WshShell.Run "C:\windows\system32\schtasks.exe /create /TN ScheduledShutdown /TR C:\Progra~1\Shutdown\Shutdown.bat /SC DAILY /ST 20:00:00 /RU SYSTEM"
    The batch file which is copied to the machine on start up each time, has to be saved in a location somewhere the vbs can contact.

    Code:
    C:\windows\system32\shutdown -s -t 300 -c "The Computer Will Shutdown In 5 Minutes, Save your Work && Log Off."
    The vbs holds the schedule creation so if you ever need to change the shutdown time it can be edited there and will deploy out on next reboot.

    Hope this is of any help to anyone.

  2. #2
    tomscaper's Avatar
    Join Date
    Jul 2006
    Posts
    814
    Thank Post
    118
    Thanked 29 Times in 15 Posts
    Rep Power
    22
    Typo in the bjFSO.DeleteFile part it should be.

    Code:
    Option Explicit
    Dim sUserName, sLogonserver, oShell, oNetwork, WshShell
    Dim sPath1, sPath2, sPath3, sPath4, objFSO, sFavPath, objFolder, objShell
    
    Set WshShell = CreateObject("WScript.Shell")
    Set oShell = CreateObject("Wscript.shell")
    Set oNetwork = WScript.Createobject("Wscript.Network")
    
    sPath1 = "\\server\batch file location\"
    sPath2 = "C:\Program Files\"
    sPath3 = "Shutdown\"
    sPath4 = "shutdown.bat"
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    On Error Resume Next
    
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    'This Part Checks to See if the Shutdown Folder is present and creates.
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    
    If objFSO.FolderExists(sPath2 & sPath3) Then
        Set objFolder = objFSO.GetFolder(sPath2 & sPath3)
    	'msgbox("Folder Exists")
    Else
        Set objShell = CreateObject("Shell.Application")
    	Set objFolder = objShell.NameSpace(sPath2) 
    	objFolder.NewFolder "Shutdown"
    	'msgbox("Folder Created")
    End If
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    'This Part Copies the shutdown batch file
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    
    If objFSO.FileExists(sPath2 & sPath3 & sPath4) Then
    objFSO.DeleteFile sPath2 & sPath3 & sPath4
    objFSO.CopyFile sPath1 & sPath4 , sPath2 & sPath3
    'msgbox("File Exists, Deleted & Copied")
    else
    objFSO.CopyFile sPath1 & sPath4 , sPath2 & sPath3
    'msgbox(" File Copied")
    set objFSO = nothing
    
    End If
    
    'msgbox("End")
    
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    'This Part Copies the shutdown batch file
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    
    WshShell.Run "C:\windows\system32\schtasks.exe /Delete /TN * /F"
    
    WshShell.Run "C:\windows\system32\schtasks.exe /create /TN ScheduledShutdown /TR C:\Progra~1\Shutdown\Shutdown.bat /SC DAILY /ST 20:00:00 /RU SYSTEM"

  3. #3
    mrforgetful's Avatar
    Join Date
    May 2006
    Posts
    1,639
    Thank Post
    7
    Thanked 15 Times in 15 Posts
    Rep Power
    23
    Nice.

    But I use an AB Tutor Control policy.

  4. #4
    tomscaper's Avatar
    Join Date
    Jul 2006
    Posts
    814
    Thank Post
    118
    Thanked 29 Times in 15 Posts
    Rep Power
    22
    Quote Originally Posted by mrforgetful View Post
    Nice.

    But I use an AB Tutor Control policy.
    I did use lanview but every now and again the service would fail and the machine would not get shutdown.
    I needed something that would shut the machine down locally rather than over the network.

  5. #5

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,867
    Thank Post
    412
    Thanked 778 Times in 651 Posts
    Rep Power
    182
    Quote Originally Posted by tomscaper View Post
    I needed something that would shut the machine down locally rather than over the network.
    <insert shutdownertron plug here>

  6. #6
    tomscaper's Avatar
    Join Date
    Jul 2006
    Posts
    814
    Thank Post
    118
    Thanked 29 Times in 15 Posts
    Rep Power
    22
    Quote Originally Posted by powdarrmonkey View Post
    <insert shutdownertron plug here>
    I had tried shutdownertron but i could never get it to work.

  7. #7

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,867
    Thank Post
    412
    Thanked 778 Times in 651 Posts
    Rep Power
    182
    If you can't make it work I'd really like to hear about it (well, within reason) in case I've made a monumental cock-up with the documentation or something. A thread in the projects forum is probably best (I've broken the mailing list while migrating servers )

  8. #8
    rh91uk's Avatar
    Join Date
    Sep 2008
    Location
    UK
    Posts
    877
    Thank Post
    137
    Thanked 132 Times in 114 Posts
    Rep Power
    36
    I found Shutdownetron to be really simple to get running - very easy to manage via the ADM. Fantastic tool for nothing - grats to powdarrmonkey.

    So that's another vote for Shutdownetron if you get it working!

  9. #9
    tomscaper's Avatar
    Join Date
    Jul 2006
    Posts
    814
    Thank Post
    118
    Thanked 29 Times in 15 Posts
    Rep Power
    22
    I was probably something i did when setting it up or mabye a permissions issue my end

  10. #10

    Join Date
    Oct 2007
    Location
    Cambridgeshire, UK
    Posts
    306
    Thank Post
    58
    Thanked 23 Times in 20 Posts
    Rep Power
    18
    Quote Originally Posted by richardharris View Post
    I found Shutdownetron to be really simple to get running - very easy to manage via the ADM. Fantastic tool for nothing - grats to powdarrmonkey.

    So that's another vote for Shutdownetron if you get it working!
    Another from me...however...the fact that it cannot wake up from standby to shutdown is a major PITA at the moment (it is my preferred scheduled shutdown option otherwise). All my machines are set to standby after a short idle time but of course then fail to shutdown when they get to the scheduled time. :-(

    Any idea of when this might be addressed in Shutdownertron? I think it was mentioned as in the pipeline a while ago ;-)

    Dave.

  11. #11
    eean's Avatar
    Join Date
    May 2006
    Location
    Seoul
    Posts
    572
    Thank Post
    71
    Thanked 57 Times in 41 Posts
    Rep Power
    31
    This is similar to a method that I used a while back (post seems to be missing from edugeek). I used psshutdown, because it also gives a cancel option. The advantage, as djones says, is that it allows the comptuer to wake up from standby. You can also set other options on the task, for example, only run when the computer has been idle for n minutes. This will prevent a prompt appearing when someone is using the comptuer.
    It should be easy to combine this with the shutdownatron idea of using an adm file. The script could read the relevant keys from the registry to get the time for shutdown.

  12. #12
    tomscaper's Avatar
    Join Date
    Jul 2006
    Posts
    814
    Thank Post
    118
    Thanked 29 Times in 15 Posts
    Rep Power
    22
    I will give shutdownertron another go.

  13. #13

    Join Date
    Dec 2007
    Posts
    149
    Thank Post
    0
    Thanked 5 Times in 5 Posts
    Rep Power
    17

    Shutdown

    I was looking for a way of deploying scheduled tasks on our workstations to run PSSHUTDOWN at 4, 4:30, 5, 5:30 and 6 with an option to cancel so that users can continue to work and work uninterrupted if the task is set only to run
    I was going to set up differnet policies for PCs in different areas of the school but it seems that all that work might have been saved by Shutdownertron.

    Just a couple of questions:
    1) Can each PC be set to shut down at multiple times so that if the user cancels it first time the second (or later) instance shuts the machine down?
    2) Did the issue about waking from standby get sorted? Does PSSHutdown address this? Can PSSHutdown be integrated with Shutdownertron Would my local scheduled task to run PSSHUTDOWN wake the PC from standby to turn it off?

    Has anyone written a batch script to remove/reinstall local scheduled tasks to do the "If idle run psshutdown" local tasks? I'm pretty confident I can do the installing the tasks but if the times get changed is it easy to remove existing tasks from a script?

    Chris



SHARE:
+ Post New Thread

Similar Threads

  1. Network Maintenance Schedule
    By SimAda00 in forum How do you do....it?
    Replies: 1
    Last Post: 9th February 2009, 03:18 PM
  2. Schedule Tasks Schtask.exe
    By timbo343 in forum General Chat
    Replies: 0
    Last Post: 14th May 2008, 05:00 PM
  3. Maintainece Schedule
    By FN-GM in forum Wiki Announcements
    Replies: 2
    Last Post: 27th March 2008, 12:40 AM
  4. Maintainece Schedule
    By Neville in forum Windows
    Replies: 18
    Last Post: 24th March 2008, 08:33 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
  •