Gold mine of Visual C++ tricks!
How to shutdown or restart a remote machine?
![]()
You can restart the machine on your table by simply pressing the restart button. But what about a remote machine? For instance, in cable-tv broadband networks, windows machines can be deployed as industrial pc’s which are located several kilometers away from the central server. So its not possible to reach the hardware and restart the pc if needed. So how can you shutdown or restart a remote pc?
![]()
You can use the function – InitiateSystemShutdown(). It will initiate the shutdown or restart process in the specified remote machine. See the following code snippet.
// Restart remote machine - RemotePC01
InitiateSystemShutdown( _T("RemotePC01"), // Machine Name.
_T("You are going to be restarted"),
5000, // timeout
TRUE, // Forcefully close applications.
TRUE ); // Restart the PC
![]()
If you need to abort the shutdown process, you can call AbortSystemShutdown().
![]()
Targeted Audience – Beginners.
| Print article | This entry was posted by Jijo Raj on June 10, 2008 at 6:42 pm, and is filed under Codeproject, Windows APIs. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 2 years ago
Jijo, Is there any way to start(switch-on) a PC from remote machine through VC++ APIs?
Additional Information on this querry
Power is already cycled.
Windows XP , SP1
VS not installed
about 2 years ago
Hello Guru,
Indeed. Everything is possible. Have a look at “Wake on lan”. Check here for how to configure it – http://www.annoyances.org/exec/show/article04-101
THen you’ve to broadcast a Magic packet to start your remote pc. For Magic packet syntax check here – http://en.wikipedia.org/wiki/Wake-on-LAN#Magic_Packet
Unfortunately there isn’t any single windows api call for the same. But i managed to find a C# sample – http://community.bartdesmet.net/blogs/bart/archive/2006/04/02/3858.aspx . I hope this helps or atleast shows some light.
Regards,
Jijo.
about 1 year ago
InitiateSystemShutdown( _T(“RemotePC01″), // Machine Name.
_T(“You are going to be restarted”),
5000, // timeout
TRUE, // Forcefully close applications.
TRUE ); // Restart the PC
This is not working from my system.Should i have to do settings before doing this from VC++
about 1 year ago
Hi Rajeev,
You should have admin privilege in the remote machine or atleast SE_SHUTDOWN_NAME privilege. Check out this link – . See the remarks section for more possible errors.
Regards,
Jijo.
about 1 year ago
Im a network admin and i want to write a c++ program that scans the network for machines needing to be restarted. For example when updates are applied and and it pompts to restart i want my program to be able to pick up on that and inform me that machine is in-need of a restart.
Thank you for your time
ryan.summey@jacob-holm.com
about 1 year ago
Well Summey, are you trying to make an application – which can install patch or service pack to all machines in your network and can restart the machine after installation?
Well, in that case i can recommend you anther cool idea. You can execute an application in a remote machine without installing any agent in that machine. Check out this article – http://www.codeguru.com/Cpp/I-N/network/remoteinvocation/article.php/c5433
All Microsoft patches supports the command line – /forcerestart and /norestart. If you have multiple patches to be installed to a machine, then execute all the patches in remote machine by passing /norestart and the last one with /forcerestart. So that after installing all patch the machine will restart itself.
Is this what you’re looking for? Or something else? Feel free to ask.
Regards,
Jijo.