Schedule shutdown

Soldato
Joined
6 May 2009
Posts
20,361
How do i get this script to not duplicate everytime it runs. The script does work but on every login will create a new task instead of just using the same one

at 23:44 /interactive /every:M,T,W,Th,F,S,Su C:\WINDOWS\system32\shutdown.exe -s -t 10

(can be tested in the run box then opening scheduled tasks, but i guess you all know this anyway)
 
You could do a delete command first,

SCHTASKS /delete /?

SCHTASKS /Delete [/S system [/U username [/P password]]] /TN taskname
[/F]

Description:
Deletes one or more scheduled tasks.

Parameter List:
/S system Specifies the remote system to connect to.

/U username Specifies the user context under
which the command should execute.

/P password Specifies the password for the given
user context.

/TN taskname Specifies the name of the scheduled task to
delete. Wildcard "*" may be used to delete
all tasks.

/F (Force) Deletes the task and suppresses
warnings if the specified task is currently
running.

/? Displays this help/usage.

Examples:
SCHTASKS /Delete /TN * /F
SCHTASKS /Delete /TN "Backup and Restore"
SCHTASKS /Delete /S system /U user /P password /TN "Start Restore"
SCHTASKS /Delete /S system /U user /P password /TN "Start Backup" /F
 
Thanks. Just what im looking for, no need to use shutdown programs or vb script that everyone else on the net has been trying to use :)

SCHTASKS /delete /TN At1 /F
at 23:44 /interactive /every:M,T,W,Th,F,S,Su C:\WINDOWS\system32\shutdown.exe -s -t 10

or just use * if there are no other tasks running
 
is there a way of making the

at 23:55 /interactive /every:M,T,W,Th,F,S,Su C:\WINDOWS\system32\shutdown.exe -s -t 10

part create the task with a specific name instead of At1? This way I could delete the specific task instead of any other tasks that have been created previously
 
you can use at to give it an id number and then use at to delete the task using the same id number.

at /?

but why do you need to keep deleting it/recreating it. can't you just set up a scheduled task for it and it'll be persistent across reboots?
 
I need to do it in a login script so it runs on 100 computers, not go onto each computer and create a scheduled task individually. Different times for different scripts too

SCHTASKS /delete /TN shutdown /F
at /shutdown 23:44 /interactive /every:M,T,W,Th,F,S,Su C:\WINDOWS\system32\shutdown.exe -s -t 10

This does not create a task called shutdown. Do you know how to make it create the task with the name shutdown (so then uplon login the shutdown will be deleted and created again)
Otherwise on each login at new task is created At1, At2, At3 etc
 
Still seems an odd way of doing it but anyway...

You're trying to use two different tools to manage this, probably best to stick with one.

AT is the old nt4 style of doing it at the cmd line.
SCHTASKS is the newer one that will actually add it in to scheduled tasks and is a lot more powerful in the options it gives you.

at /shutdown will not work as shutdown is a name not an id number.
the 'at /?' was for you to type at the cmd line so you can see the syntax, not to replace the ? with a word.

schtasks /? at the cmd line will also show you the options for that.

I suggest looking at the options/syntax and picking the one that best suits your need and then just using that. Both should be be able to create and delete their own tasks.

Maybe also look at doing this as some kind of run once deploy. Seems a bit odd having to delete and create it each time a user logs on and off.

Either that or set up all tasks, or script a job, on a server somewhere that does the shut downs remotely.
 
Back
Top Bottom