Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


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

Posted on 2009-04-08
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 \\domain.com\NETLOGON (where domain.com 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.
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


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

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

Independent Software Vendors: 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!

Question has a verified solution.

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

Uncontrolled local administrators groups within any organization pose a huge security risk. Because these groups are locally managed it becomes difficult to audit and maintain them.
Group policies can be applied selectively to specific devices with the help of groups. Utilising this, it is possible to phase-in group policies, over a period of time, by randomly adding non-members user or computers at a set interval, to a group f…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

636 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