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.
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks


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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
Let's recap what we learned from yesterday's Skyport Systems webinar.
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Suggested Courses

771 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