Solved

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

Posted on 2009-04-08
10
881 Views
Last Modified: 2012-05-06
Hello
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).

Regards
0
Comment
Question by:stalliondz
  • 5
  • 4
10 Comments
 
LVL 27

Expert Comment

by:bluntTony
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)
0
 
LVL 27

Expert Comment

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

Author Comment

by:stalliondz
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.
0
 

Author Comment

by:stalliondz
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
0
 
LVL 27

Expert Comment

by:bluntTony
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...
0
 

Author Comment

by:stalliondz
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.
0
 
LVL 9

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...
0
 
LVL 27

Accepted Solution

by:
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

Next

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

Open in new window

0
 

Author Comment

by:stalliondz
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.
0
 
LVL 27

Expert Comment

by:bluntTony
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...
0

Join & Write a Comment

Suggested Solutions

Learn about cloud computing and its benefits for small business owners.
Synchronize a new Active Directory domain with an existing Office 365 tenant
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 to another domain controller. Log onto the new domain controller with a user account t…

760 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

16 Experts available now in Live!

Get 1:1 Help Now