[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 921
  • Last Modified:

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

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
stalliondz
Asked:
stalliondz
  • 5
  • 4
1 Solution
 
bluntTonyCommented:
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
 
bluntTonyCommented:
All Authenticated users have read access to this store, so will all be able to read this script.
0
 
stalliondzAuthor Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
stalliondzAuthor Commented:
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
 
bluntTonyCommented:
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
 
stalliondzAuthor Commented:
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
 
Derek Schauland (Microsoft MVP)IT ConsultantCommented:
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
 
bluntTonyCommented:
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
 
stalliondzAuthor Commented:
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
 
bluntTonyCommented:
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

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now