ShutDown PCs in domain at a specific time (VBS script available)

Posted on 2009-04-08
Last Modified: 2012-05-06
We have 200 Computer (both Vista and Xp clients) connected in a domain ( running Windows Server 2003 R2 SP2), and i have a script (vbs)  that Once it's run it will shut down the computer automaticaly.
I would like to know if there is any way to run that script from a centralized location, and the script file will be shared in a shared location on the server. so that it will be run automaticaly by the client from the shared location in the server at a specific time (example 7 PM after working hours).

Question by:stalliondz
  • 5
  • 4
LVL 27

Expert Comment

ID: 24096864
If you want it in a centralised location, put it in NETLOGON - this is a repository for centrally accessible scripts.
Access netlogon through the UNC \\\NETLOGON (where is your domain DNS name)
LVL 27

Expert Comment

ID: 24096871
All Authenticated users have read access to this store, so will all be able to read this script.

Author Comment

ID: 24096908
But My Question is HOW to run that script at a Specific Time ( Example 7 PM Every day i want that script to Run), i can include the script here as an attachement if that can help.

Author Comment

ID: 24096920
But my Question is HOW to run that srcipt at a specific time ( example: i want that script to run on all the client PCs at 7 PM every day).
I can include the script code that i am talking about here , if that's Nessesary
LVL 27

Expert Comment

ID: 24097110
Oh, right, schedule a task to do this. For example, from the command line:
at 19:00 /every:monday,tuesday,wednesday,thursday,friday shutdown -s -f
This task will schedule a job to shutdown the machine every weekday at 19:00. You might not need to call your script if the built in shutdown.exe will suffice.
Perhaps a better way would be to schedule a single job on a server which remotely shuts down all the machines itself. You can shutdown remote machines using shutdown.exe, so you could write a script which counts machines in particular OUs, and attempts to shut them down.
Let us know if this is of interest...
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.


Author Comment

ID: 24097380
Thnaks alot BluntTony for your support.

Can we write a script that will be deployed as a Startup Script that will Configure the Schedule Tast with that. in other words a script that will Run that command without me having to go to each PC and type it individualy. just script it and deploy it as a  "Startup" Group Policy from the Server and it will schedual that task !! can that be done !!! and how to script that.

Expert Comment

by:Derek Schauland
ID: 24098352
You could probably include the AT command in a logon script, but it is likely you will only need to set it once rather than at every logon...
LVL 27

Accepted Solution

bluntTony earned 500 total points
ID: 24099293
You could simply add the following to a bat file:
at 19:00 shutdown.exe -f -s -t 30
Apply this as a login script, and a single task will be scheduled for that day to shut the machine down. The only problem with doing this is that if a user logs in numerous times, or shuts down before 19:00, then you could end up with multiple tasks on the system. A better way would be to check for any currently scheduled tasks, then apply a task if one isn't already scheduled. VB script below.
It basically checks for any commands with the word 'shutdown' in the command.

Set objShell = CreateObject("Wscript.Shell")

set objWMI = GetObject("winmgmts:\\.\root\cimv2")

set colScheduledJobs = objWMI.ExecQuery("Select * from Win32_ScheduledJob")

For each objJob in colScheduledJobs

	If InStr(UCase(objJob.command),"SHUTDOWN") > 0 Then	booFound = True


If Not booFound Then objShell.Run("%systemroot%\system32\at 19:00 shutdown.exe -s -f -t 30")

Open in new window


Author Comment

ID: 24105500
I have tried to emplement that script and save it as a Bat File, but when i run it nothing happens and it doesn't add the task to the Schadualed Tasks.   i'm trying it on WIndows XP Sp3 Client and it's not working.
LVL 27

Expert Comment

ID: 24131148
The 7 lines of code is VB Script - save it as a vbs file, e.g. sched_shutdown.vbs. Then apply this as a login script. Sorry - I may not have been clear.
The last post gave two options. the first was simply at 19:00 shutdown.exe -f -s -t 30 as a bat file. This will blindly schedule a task to shut the machine down at 19:00 that day. Simple one liner. The downside to this is that you could end up with multiple tasks sitting on the machine if a number of users log in during the day (a task will be applied on each login).
The second, the vbs, has logic which will check whether this task has already been scheduled. If not, it schedules it. If one have already been scheduled, then it does nothing. So you only ever have one task.
Try running the vbs script manually to check that it is working. To check a task has been scheduled, just type 'at' from the command line...

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

867 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now