talama

Remotely restart (or shutdown) computers from a text file of

May 7th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Set WSHShell = WScript.CreateObject("WScript.Shell")
  2. Set oFS = CreateObject("Scripting.FileSystemObject")
  3.  
  4. strWarning = "Due to network maintenance, this computer must be restarted. You have 5 minutes to save your work from the start of this countdown. Sorry for any inconvenience caused. "
  5. strDelay = 300  'Delay given in seconds; change this value to your preference, or set it to 0 to give no delay at all
  6.  
  7. 'Open a text file of computer names
  8. 'with one computer name per line
  9. Set oTS = oFS.OpenTextFile("C:\computers.txt")
  10.  
  11. 'go through the text file
  12. Do Until oTS.AtEndOfStream
  13.  'get the next computer name
  14. 'store it in variable strCompname
  15. strCompname = oTS.ReadLine
  16.         WshShell.Run "C:\Windows\System32\shutdown.exe -m \\" & strCompname & " -r -c " & Chr(34) & strWarning & Chr(34) & " -t " & strDelay    'Replace the "-r" switch with "-s" to make the computers shutdown instead
  17. Loop
  18. 'close the text file
  19. oTS.Close
Add Comment
Please, Sign In to add comment