Page 1 of 1

Restart Computers and Send a Log

Posted: 27 Apr 2020 15:16
by Zuhan
Hello,

I am in need of assistance. I'm trying to make a batch file to restart computers on my network and send a log of what computers successfully restarted and what computers were not. I know to restart the command is shutdown -r but I'm not sure how to get it to send a log file. A quick rundown I am trying to do is:

At (Time) warn user logged in that computer will restart in 30 minutes and to save their work before the restart.
At (Time) warn the user that the computer will restart in 5 minutes and to save their work before the restart.
At (Time) shutdown -r
Upon successful/unsuccessful restart send a log to (Server/Folder)

If you need more information please let me know.

Re: Restart Computers and Send a Log

Posted: 30 Apr 2020 09:11
by Zuhan
Anyone?

Re: Restart Computers and Send a Log

Posted: 01 May 2020 05:31
by penpen
I suggest you to run the task rom a login on another computer with enough rights and "msg.exe" installed (which usually is a professional or enterprise version of windows 10 for example), else you have to take care of restarting the batch on reboot.
For all but the last task, you could create something like that batch file:

Code: Select all

set "computer=DESKTOP-007"
msg *  /Server:%computer% "This PC will restart in 30 minutes. Save your work before the restart."
timeout /t 1500 /nobreak
msg *  /Server:%computer% "This PC will restart in 5 minutes. Save your work before the restart."
timeout /t 270 /nobreak
shutdown /r /m \\%computer%
But i'm not sure how to perform the last task:
I'm not aware of any way to execute a command on reboot of a pc (although there must be one as updates use that regularly).

You might want to just wait a minute or so (depends on how long the target pc needs to reboot, which could vary extremely if for example some updates are triggered by reboot) and then just use "psexec.exe" to start another batch on the pc you just restarted.


penpen

Re: Restart Computers and Send a Log

Posted: 01 May 2020 17:27
by Zuhan
Thanks for the code. Someone suggested I put the batch file onto a server that doesn't shut off. Unfortunately on my network I do not have msg.exe installed and cannot instal it due to the type of network I am on. As for the log on bootup I could maybe create a batch file to copy the event log on startup and send it to one of our servers.