Jump to content

Reboot all PCs via task scheduler


Recommended Posts

Is it possible to reboot all PCs whether a user is logged on or not using a group policy task scheduler? i know how to set up the task via policy but cant workout how to restart all pcs.....so far i have:

echo shutdown -r
at 01:00 /every:01

this is in a batch file that runs when the system starts. I would like to restart everyday at 1am

thanks

Link to comment
Share on other sites


Is it possible to reboot all PCs whether a user is logged on or not using a group policy task scheduler? i know how to set up the task via policy but cant workout how to restart all pcs.....so far i have:

echo shutdown -r
at 01:00 /every:01

this is in a batch file that runs when the system starts. I would like to restart everyday at 1am

thanks

Well, actually that line in a batch:

echo shutdown -r
at 01:00 /every:01

does not make much sense, the first line will ECHO to the screen the string "shutdown -r", and the second line is missing the actual COMMAND that needs to be executed, besides the missing "\\computername"

See here the correct syntax for the AT command:

http://www.ss64.com/nt/at.html

As reported there, AT is an old command, the "new" one is SCHTASKS:

http://www.ss64.com/nt/schtasks.html

And shutdown.exe has more options, doing a shutdown of remote computers without checking them can lead to either a "not performed" shutdown (i.e. the user stopped the countdown) or a "bad" shutdown, where services or applications are not closed properly, that could lead to data leak:

http://www.ss64.com/nt/shutdown.html

Personally I would use PSShutdown:

http://www.microsoft.com/technet/sysintern...PsShutdown.mspx

that has more options, including one to shutdown every computer in the Domain (\\*).

With all due respect, judging from your questions, here and on this other thread:

http://www.msfn.org/board/index.php?showtopic=88691&hl=

you might want to study a little bit more about batch language and more generally commands in NT/2K/XP before attempting using them.

The two already referenced sites:

http://www.robvanderwoude.com/index.html

http://www.ss64.com/

are very good starting points.

jaclaz

Link to comment
Share on other sites

Is it possible to reboot all PCs whether a user is logged on or not using a group policy task scheduler? i know how to set up the task via policy but cant workout how to restart all pcs.....so far i have:

echo shutdown -r
at 01:00 /every:01

this is in a batch file that runs when the system starts. I would like to restart everyday at 1am

thanks

Well, actually that line in a batch:

echo shutdown -r
at 01:00 /every:01

does not make much sense, the first line will ECHO to the screen the string "shutdown -r", and the second line is missing the actual COMMAND that needs to be executed, besides the missing "\\computername"

See here the correct syntax for the AT command:

http://www.ss64.com/nt/at.html

As reported there, AT is an old command, the "new" one is SCHTASKS:

http://www.ss64.com/nt/schtasks.html

And shutdown.exe has more options, doing a shutdown of remote computers without checking them can lead to either a "not performed" shutdown (i.e. the user stopped the countdown) or a "bad" shutdown, where services or applications are not closed properly, that could lead to data leak:

http://www.ss64.com/nt/shutdown.html

Personally I would use PSShutdown:

http://www.microsoft.com/technet/sysintern...PsShutdown.mspx

that has more options, including one to shutdown every computer in the Domain (\\*).

With all due respect, judging from your questions, here and on this other thread:

http://www.msfn.org/board/index.php?showtopic=88691&hl=

you might want to study a little bit more about batch language and more generally commands in NT/2K/XP before attempting using them.

The two already referenced sites:

http://www.robvanderwoude.com/index.html

http://www.ss64.com/

are very good starting points.

jaclaz

Ok Mr Jaclaz, i see what you mean after thinking about it and reading on it i have come up with the below code:

Schtasks /Create /SC Daily /RU System /MO 7 /TN TestReboot /TR "\\server\share$\task\psshutdown -r" /st 00:40:00 /SD 15/12/2006

This works i.e. adds the task in the scheduler but the status comes up as Could not Start. Im logged on as administrator (for testing) and have copied relevant .dll and exe to the same folder. If i type psshutdown -r via the command line - it works.

Thanks

edit: I have also tried to replace \\server\share$\task\psshutdown -r with C:\windows\system32\shutdown -r with the same issue. I checked the Schedlgu.txt file and have 0x80070002 The system cannot find the file specified. Try using the task page browse button to locate the application, but reading on this error

Edited by Bad boy Warrior
Link to comment
Share on other sites

Try this:

Schtasks /Create /SC Daily /RU System /MO 7 /TN TestReboot /TR "\\server\share$\task\testshut.cmd" /st 00:40:00 /SD 15/12/2006

and create in

\\server\share$\task\

A file named testshut.cmd with this contents:

@echo off
psshutdown -r

That should work, the problem is that you cannot pass parameters with the /TR switch, you can only give it a file to execute.

jaclaz

Link to comment
Share on other sites

Also i don't think the system user will have acces to \\server\share$\task\. So it'll never run. You have to use either an account with ntfs and share rights on \\server\share$\task\ or copy the files needed on each computer.

Link to comment
Share on other sites

Thanks everyone!!

@Jaclaz

I tried that but still didnt work :realmad:

In my tasks directory i have

pdh.dll

psshutdown.exe

testshut.cmd

StartTask.bat

Doubleclick startask.bat and runs fine - adds the entry to task scheduler. But when the time comes it shows up an error "could not start" with the same error as before. Changed testshut.cmd to a .bat file - same error changed both files to .cmd and although they run by the command line without a problem they dont run as they should by a task and both run with a .bat extension if i double click them. The directory is in a test directory for now it does have full admin rights and im running as a domain admin.

thanks

Link to comment
Share on other sites

Well, if I get it right you have some problems with .cmd files.

A batch file should run if double clicked BOTH if it has .bat or .cmd extension.

Once you have fixed the above, you might want to try with this batch (that has no external commands):

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
ECHO Hallo, I am a batch file, and I am running!
ECHO.
ECHO I was invoked as %0, but my real name is %~nx0....
ECHO.
ECHO ...and, to be picky, my FULL name is %~f0
ECHO-
ECHO I live in directory %~dp0 and I'll terminate myself
ECHO as soon as you press any key.
PAUSE

If the above works, and it should, modify your testshut.cmd (or testshut.bat) as follows:

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
ECHO Hallo, I am a batch file, and I am running!
ECHO.
ECHO I was invoked as %0, but my real name is %~nx0....
ECHO.
ECHO ...and, to be picky, my FULL name is %~f0
ECHO-
ECHO I live in directory %~dp0, and I'm going to run %~dp0psshutdown -r
ECHO as soon as you press any key.
PAUSE
%~dp0psshutdown -r

If it did not work, try using more "common" paths, like the ones given in the example by MS:

http://www.microsoft.com/resources/documen...s.mspx?mfr=true

C:\Apps

if it works, it is a problem in the PATH given as "\\server\share$\task\"

jaclaz

Edited by jaclaz
Link to comment
Share on other sites

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...