Answered by:
VBS Help!!!
-
Hi Everyone, Hope you guys can help.
I have taken one of the generic vbs scripts available online and am trying to tweak it for our needs. Currently I work in an organization that has about 400 computers. Our higher ups have complained about power consumption so we are trying to work on a code that assists with shutting computers down.
We have no issues with running the standard script and getting the display message and setting a time but they want something a little more advanced.
Basically we are looking to run this script everyday at 1700. We would like the computers to shut off at 22:00 but only have a 15 minute warning instead of a 5 hour warning to prevent users from being scared. I would like it to pull the list of computers from a text document which I specify, this is already configured but just wanted to put it out there. We would also like a custom message to appear to each user. If possible also if the user is still working on the machine to give them the option to abort (Maybe with shutdown -a), but im not sure this can be done.
Thanks for the help guys!
Here is the code I've worked on:Set WSHShell = WScript.CreateObject("WScript.Shell") Set oFS = CreateObject("Scripting.FileSystemObject") strWarningDelay = 10 strWarning = "In an effort to reduce power consumption your computer will be shut down at 22:00 daily. Please save all of your work!" strDelay = 30 'Open a text file of computer names 'with one computer name per line Set oTS = oFS.OpenTextFile("C:\Viper\ONE COMPS.txt") 'go through the text file Do Until oTS.AtEndOfStream 'get the next computer name 'store it in variable strCompname strCompname = oTS.ReadLine WshShell.Run "C:\Windows\System32\shutdown.exe -m \\" & strCompname & " -s " " -t " & strWarningDelay " -c " " -t " & strDelay Loop 'close the text file oTS.Close
Question
Answers
-
As for the message I believe its the -t or -m command in the line, but it does display a message on a remote computer. Have done it several times already.
Anyways, I would like to thank you for your time. Just a middle schooler trying to get my homework done ;)
The shutdown comamnd displays a message but it cannot wait 4.75 hours and then prompt again. It is just not possible.
YOu need to rethink this whole project. What you are being asked sounds like a test to see if you understand Windows but maybe your bosses just don't understand WIndows. I have seen that with bosses and with teachers. They just think they are being cool.
I do not understad why a required daily shutdown would not just be permanently scheduled. It would run and prompt the current user. Of course if no one is logged in youy would need a backup script to to run at teh drop dead time under the system to force a shutdown.
Tis is a problem fo rWIndows and always has been. There are KB articles addressing this issue. The answer has always been to acquire a third party shutdown service which can be configured for multiple messages and rules and is configured via Group Policy or via a config file.
Ask your bosses to explain exactly what each step is intended to accomplish and explain that only scripts running as the user can display messages to a user.
Ther is a nother brute force method and that uses the net message utility to send a message to all use5rs on a machine. This cannot be used to abort the shutdown but it will allow remote messaging. It is not 100% reliable.
A script running under the scheduler that is executed when the user logs in is the better and safer approach for a simple solution because you can allow the user to request a delay for as long as needed plus you can force an outcome if the user goes home and forgets to give you permission.
¯\_(ツ)_/¯
- Marked as answer by RandalB91 Tuesday, March 12, 2013 6:49 PM
All replies
-
-
-
-
They want is exactly as stated above. They want the command to be run AT 1700 with the message delayed until 2145 which then warns them its being shut down. At 2200 the computers shut down.
Schedule the task to run a 21:45 or schedule it to run at 17:00 and put a sleep command that waits for the remainder of the time:
sec = (((60 * 60) * 4) + (45 * 60))
For i = 0 to sec
WScript.Sleep 1000
NextThis will calculate the number of seconds until the message.
Just scheduling it is much more rational but I guess your bosses are a little weird. Since we invented computersz it is easier to use the system scheduler than it is to count done things.
Of course you could tells us that this is really another homework question that you want someone to do for you.
By the way. You cannot sena mesage to a remote computer with VBScript so that part of the assignment is not possible.
To display a message in teh user session you need to schedule a script to run ON the remote machine and to run as the logged in user. This script can display messages. The script you have posted cannot display remote messages.
¯\_(ツ)_/¯
-
They want is exactly as stated above. They want the command to be run AT 1700 with the message delayed until 2145 which then warns them its being shut down. At 2200 the computers shut down.
Schedule the task to run a 21:45 or schedule it to run at 17:00 and put a sleep command that waits for the remainder of the time:
sec = (((60 * 60) * 4) + (45 * 60))
For i = 0 to sec
WScript.Sleep 1000
NextThis will calculate the number of seconds until the message.
Just scheduling it is much more rational but I guess your bosses are a little weird. Since we invented computersz it is easier to use the system scheduler than it is to count done things.
Of course you could tells us that this is really another homework question that you want someone to do for you.
By the way. You cannot sena mesage to a remote computer with VBScript so that part of the assignment is not possible.
To display a message in teh user session you need to schedule a script to run ON the remote machine and to run as the logged in user. This script can display messages. The script you have posted cannot display remote messages.
¯\_(ツ)_/¯
As for the message I believe its the -t or -m command in the line, but it does display a message on a remote computer. Have done it several times already.
Anyways, I would like to thank you for your time. Just a middle schooler trying to get my homework done ;)
- Edited by RandalB91 Tuesday, March 12, 2013 7:19 AM
-
As for the message I believe its the -t or -m command in the line, but it does display a message on a remote computer. Have done it several times already.
Anyways, I would like to thank you for your time. Just a middle schooler trying to get my homework done ;)
The shutdown comamnd displays a message but it cannot wait 4.75 hours and then prompt again. It is just not possible.
YOu need to rethink this whole project. What you are being asked sounds like a test to see if you understand Windows but maybe your bosses just don't understand WIndows. I have seen that with bosses and with teachers. They just think they are being cool.
I do not understad why a required daily shutdown would not just be permanently scheduled. It would run and prompt the current user. Of course if no one is logged in youy would need a backup script to to run at teh drop dead time under the system to force a shutdown.
Tis is a problem fo rWIndows and always has been. There are KB articles addressing this issue. The answer has always been to acquire a third party shutdown service which can be configured for multiple messages and rules and is configured via Group Policy or via a config file.
Ask your bosses to explain exactly what each step is intended to accomplish and explain that only scripts running as the user can display messages to a user.
Ther is a nother brute force method and that uses the net message utility to send a message to all use5rs on a machine. This cannot be used to abort the shutdown but it will allow remote messaging. It is not 100% reliable.
A script running under the scheduler that is executed when the user logs in is the better and safer approach for a simple solution because you can allow the user to request a delay for as long as needed plus you can force an outcome if the user goes home and forgets to give you permission.
¯\_(ツ)_/¯
- Marked as answer by RandalB91 Tuesday, March 12, 2013 6:49 PM
-
You can copy a script to the administrative shares (C$, ADMIN$ = windir) and schedule it with task scheduler in 1 second. Here's a script that lists tasks in the root folder and deletes tasks starting with username. The computer name is serenity.
Set service = CreateObject("Schedule.Service")
call service.Connect("Serenity")' Get the task folder that contains the tasks.
Dim rootFolder
Set rootFolder = service.GetFolder("\")
Dim taskCollection
Set taskCollection = rootFolder.GetTasks(0)Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshEnv= WshShell.Environment("Process")Username = WshEnv("USERNAME")
Dim numberOfTasks
numberOfTasks = taskCollection.CountIf numberOfTasks = 0 Then
Wscript.Echo "No tasks are registered."
Else
WScript.Echo "Number of tasks registered: " & numberOfTasks
Dim registeredTask
For Each registeredTask In taskCollection
msgbox registeredTask.Name
If Left(registeredTask.Name,Len(username)) = Username then
msgbox "Deleting " & registeredTask.Name
RootFolder.DeleteTask registeredTask.Name, 0
End If
Next
End IfDavid Candy
-
As for the message I believe its the -t or -m command in the line, but it does display a message on a remote computer. Have done it several times already.
Anyways, I would like to thank you for your time. Just a middle schooler trying to get my homework done ;)
The shutdown comamnd displays a message but it cannot wait 4.75 hours and then prompt again. It is just not possible.
YOu need to rethink this whole project. What you are being asked sounds like a test to see if you understand Windows but maybe your bosses just don't understand WIndows. I have seen that with bosses and with teachers. They just think they are being cool.
I do not understad why a required daily shutdown would not just be permanently scheduled. It would run and prompt the current user. Of course if no one is logged in youy would need a backup script to to run at teh drop dead time under the system to force a shutdown.
Tis is a problem fo rWIndows and always has been. There are KB articles addressing this issue. The answer has always been to acquire a third party shutdown service which can be configured for multiple messages and rules and is configured via Group Policy or via a config file.
Ask your bosses to explain exactly what each step is intended to accomplish and explain that only scripts running as the user can display messages to a user.
Ther is a nother brute force method and that uses the net message utility to send a message to all use5rs on a machine. This cannot be used to abort the shutdown but it will allow remote messaging. It is not 100% reliable.
A script running under the scheduler that is executed when the user logs in is the better and safer approach for a simple solution because you can allow the user to request a delay for as long as needed plus you can force an outcome if the user goes home and forgets to give you permission.
¯\_(ツ)_/¯
Thats what I ended up doing for my homework assignment :). I ran everything under task scheduler and its supposed to go off tonight, hopefully I get an A guys! :)

