Jump to content

Recommended Posts

Posted

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.

 


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.

 

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.

Posted

Typo in the bjFSO.DeleteFile part it should be.

 

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"

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

  • 2 weeks later...
Posted
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 :()
Posted

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! :)

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

Posted

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.

  • 2 weeks later...
Posted

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...