Restart Computers and Send a Log

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Zuhan
Posts: 10
Joined: 03 Apr 2020 14:33
Location: Yokosuka, Japan

Restart Computers and Send a Log

#1 Post by Zuhan » 27 Apr 2020 15:16

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.

Zuhan
Posts: 10
Joined: 03 Apr 2020 14:33
Location: Yokosuka, Japan

Re: Restart Computers and Send a Log

#2 Post by Zuhan » 30 Apr 2020 09:11

Anyone?

penpen
Expert
Posts: 1809
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Restart Computers and Send a Log

#3 Post by penpen » 01 May 2020 05:31

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

Zuhan
Posts: 10
Joined: 03 Apr 2020 14:33
Location: Yokosuka, Japan

Re: Restart Computers and Send a Log

#4 Post by Zuhan » 01 May 2020 17:27

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.

Post Reply