Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Scripts to shut down PC?

Posted on 2006-05-25
23
Medium Priority
?
1,255 Views
Last Modified: 2012-08-13
Hey there.  I was wondering if any of you knew a way I can have a workstation automatically shut down on Friday nights at 6pm?  Also, get it to prompt the user and give them a set amount of time to either deny the shut down if someone is using the workstation.  Links and tutorials on how to write this script will be great too.
0
Comment
Question by:warriorfan808
  • 13
  • 9
23 Comments
 
LVL 24

Expert Comment

by:Kenneniah
ID: 16763381
First download psshutdown from http://www.sysinternals.com/utilities/psshutdown.html
Extract it to something like C:\Pstools. You can put the file anywhere, just remember to change the path in the following command for scheduling it...
Then from a command prompt type:

schtasks /create /tn "Shutdown" /tr "c:\pstools\psshutdown.exe -c -f" /ru system /sc weekly /d FRI /st 18:00:00
0
 
LVL 24

Expert Comment

by:Kenneniah
ID: 16763404
By default psshutdown gives 20 seconds for the user to hit cancel. If you want to change it, add the -t option. For example for 60 seconds.....

schtasks /create /tn "Shutdown" /tr "c:\pstools\psshutdown.exe -c -f -t 60" /ru system /sc weekly /d FRI /st 18:00:00

To test the task after creating it just run....

schtasks /run /tn shutdown
0
 
LVL 16

Expert Comment

by:craylord
ID: 16763536
There is a builtin command in Windows XP. It's called shutdown. Open a dos box and type shutdown /? for information.
A line such as this would inform the user the computer will shut down in 5 minutes.

shutdown -s -t 300 -c "This computer is scheduled to shutdown after 6:00. Save and close all documents to prevent data loss." -f

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 24

Expert Comment

by:Kenneniah
ID: 16763621
The problem with the built-in shutdown, is it does not work when scheduled to run under the System account, and a user is not logged in at the time.
0
 
LVL 24

Expert Comment

by:Kenneniah
ID: 16763643
0
 
LVL 1

Author Comment

by:warriorfan808
ID: 16763902
After you schedule it, how do you take it off?  The reason I"m asking is because I wanted to test it out.
0
 
LVL 24

Expert Comment

by:Kenneniah
ID: 16764089
schtasks /delete /tn shutdown
0
 
LVL 1

Author Comment

by:warriorfan808
ID: 16764224
I just ran a test and it didn't work.

Here is what I did.

Downloaded the tools, extracted to

C:\Pstools\

went to the run command and typed:

schtasks /create /tn "Shutdown" /tr "c:\Pstools\psshutdown.exe -c -f -t 120" /ru system /sc weekly /d THURS /st 10:15:00

I was using my computer at the time.  Is this why it didn't shut down?
0
 
LVL 1

Author Comment

by:warriorfan808
ID: 16764238
Also, is there a command to see all the scheduled tasks?
0
 
LVL 24

Expert Comment

by:Kenneniah
ID: 16764268
Was it 10am where you are or 10pm?
0
 
LVL 24

Expert Comment

by:Kenneniah
ID: 16764276
To see scheduled tasks, just run schtasks with no options.
0
 
LVL 24

Expert Comment

by:Kenneniah
ID: 16764296
Hmm you should have gotten an error message when you used your command. Are you running this from Start|Run or from a command prompt? If from Run, do it from a command prompt instead so you can see any error messages.

But the problem in your command is THURS, change it to THU
0
 
LVL 1

Author Comment

by:warriorfan808
ID: 16764359
Thanks man.

I was looking on the site.

Where does schtasks/create /tn "Shutdown"/tr  come from?  Is that a Windows command

also what does

ru --I know u is for user, but ru?
sc - scheduled calendar?
st - scheduled time?

Where did you get all these?  Is there a place I can go so I can print them all out?
0
 
LVL 1

Author Comment

by:warriorfan808
ID: 16764362
sorry forgot one other thing,

is it:

mon
tues
wed
thu
fri
sat
sun

??

do they have to be capitalized?
0
 
LVL 24

Expert Comment

by:Kenneniah
ID: 16764429
Schtasks is built into Windows.
/create - just means to make a new task
/tn - just makes up a name for the task, it can be anything you want
/tr - is the task to run
/ru - the user the task runs as, there is also a /u option to specify a user context to run under. For example if you used both switches, it would run under the /u users context, with the /ru users security privelages
/sc - just short for schedule, weekly, daily, monthly etc.
/st - yup, time to start the task.

You can just type schtasks /? in a command prompt to see help info also, but for some indepth stuff......

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/schtasks.mspx?mfr=true
0
 
LVL 24

Expert Comment

by:Kenneniah
ID: 16764480
Correct on the days of the week except for tuesday. All are 3 letter abbreviations, so "tue", and no capitalization doesn't matter.
In the command prompt after you've created a task just type schtasks and  it will list any scheduled tasks, and also tell you the next time it will run.
0
 
LVL 1

Author Comment

by:warriorfan808
ID: 16764750
Just to make sure, would it work to create multiple shut down times?  I could probably just test it.  By the way, I did test the shutdown and it worked great.

What I mean by multiple shutdown times.

If the user clicks to cancel, then he will be prompted to shut down again at 7:00pm, 8:00pm, so on and so forth until either he walks away from the computer and lets it shut itself down or he shuts the machine down himself.

Is it easier to make multiple tasks or could it be done with one line.

If I created multiple tasks, would I just create different names?
tn "Shutdown1" /tr
tn "Shutdown2" /tr
tn "Shutdown3" /tr

etc.

Thanks a lot Kennenah, you're a lot of help.  Wish I could give you more than 500 points
0
 
LVL 24

Expert Comment

by:Kenneniah
ID: 16764863
Hmm, yeah that might not be a bad idea. Yep, just different names and times. I tried thinking of a way to do that with just one task, but can't think of any. An hourly schedule won't allow the /d option for day, so it would just keep running every hour until you deleted the task. So I then thought about using a scheduled task that on every friday creates an hourly scheduled task at 6:00 with a /sd and /ed using the %date% variable, but that would be a pain since you've had to edit the %date% variable in a batch file to make it in the right format. Hehe it probably could be done, but would end up being more difficult then just scheduling psshutdown at multiple times.

Most welcome, and points aren't a big deal. I'm just here to help and to give me something to do when I don't have a lot of work here :)
0
 
LVL 1

Author Comment

by:warriorfan808
ID: 16764911
Cool.  You'll probably hear a lot from me.  I'm far below the levels of the guys on here.
0
 
LVL 1

Author Comment

by:warriorfan808
ID: 16764923
Before I close this thread.  Have you run into any problems without using the f switch?  I mean, have there been hangs if the workstations haven't saved their work?  I would hate for someone to leave on their computer and then lose all their work.
0
 
LVL 24

Accepted Solution

by:
Kenneniah earned 2000 total points
ID: 16765003
Well, yeah it can happen. If someone left an application open with unsaved data, there's a chance they could lose it. There's also a chance they could even if you don't specify the -f switch, as not all programs stop a shutdown. However, we just tell our users that if they leave something unsaved there's a chance they could lose it, and it's their fault at that point not ours. While we try to keep the users as happy as possible etc, in some situations we have to be rigid like that. We have over 5000 computers here, and we have things that we need to do while users are gone that sometimes require reboots. Especially our patch and update management system. Many security updates require reboots, and if we didn't force the installs and reboots at night, it could be quite awhile before the update gets applied, and meanwhile security might be breeched, viruses spread etc. Finding the middile ground between customer service to users, and getting done what needs to be done can be a fine balancing act sometimes :)
0
 
LVL 1

Author Comment

by:warriorfan808
ID: 16765037
Oh awesome.  So you all came up with an estimated amount of time it should take to run all updates and installations and then forced the workstation to reboot, just in case it required a reboot?  I take it your'e using a few WSUS Servers?
0
 
LVL 24

Expert Comment

by:Kenneniah
ID: 16765570
We used to use SUS, and just set the setting for it to install updates at 3am and reboot if necessary. Now we use Shavlik for patch management, and Radia for pushing applications etc.
I never have used psshutdown in this manner, but have used it quite a few different situations.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you build your web application in Visual Studio you'll get at least a few binaries, or .DLL, files in your bin folder. However, there is more compiling to be done. Normally this would happen when an ASP.NET resource within the web site is request…
Migration of Exchange mailbox can be done with the ExProfre.exe tool. But at times, when the ExProfre.exe tool migrates the Exchange Server user profile, it results in numerous synchronization problems. Synchronization error messages appear in the e…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question