Shutting down workstations


This time is about to shut down a network machine. Of course, we have to use InitiateSystemShutdown routine. The job is done in the sample dialog by pressing Shutdown button. Also the dialog with Cancel event armed can be useful sometimes (think at stored procedures, transactions, etc.).



#include <what_you_need.h>

void 
CShutdownDlg::OnShutdown() 
{
	HTREEITEM 
		hSel  = m_treeWksta.GetSelectedItem(),	//	tree items (selected workstation)
		hRoot = m_treeWksta.GetRootItem();	//	root (network neighborhood)

	if(hRoot == hSel)
		return;

	CShutdownParamDlg dlgShutdown(this);		//	Here we configure how to shutdown workstation:
	if(dlgShutdown.DoModal() == IDCANCEL)		//	force close, reboot, timeout, and user message
		return;

	BOOL bShutdown = 
		InitiateSystemShutdown
			(
				(LPSTR)(LPCTSTR)m_strWkstaName, 
				(LPSTR)(LPCTSTR)dlgShutdown.m_strMessage, 
				dlgShutdown.m_nTimeout, 
				dlgShutdown.m_fForce, 
				dlgShutdown.m_fReboot
			);
	if(!bShutdown)
		ShowLastError();			//	Usually: not enough privileges
	else
	{
		CShutdownParam shdwn;			//	Pass a structure to wait for abort thread
		shdwn.m_nTimeout	= dlgShutdown.m_nTimeout;
		shdwn.m_strMachineName	= m_strWkstaName;

		//	Show to the user dialog with Cancel button
		CEventDlg dlg(WaitForShutdown, (LPVOID)&shdwn);
		//	If user pressed Cancel, dismiss
		if (dlg.DoModal() != 0)
			AbortSystemShutdown((LPSTR)(LPCTSTR)m_strWkstaName);
	}
}

Download demo project - 25 KB

History



Comments

  • system monitoring

    Posted by Legacy on 07/29/2003 12:00am

    Originally posted by: Milan

    i am seeking for the sourcecode to monitor the clients of the network and shut down the client side if required from the server side. i want the code in Java language. I am hoping for your cooperation

    Reply
  • Problem in exanding the tree

    Posted by Legacy on 07/21/2003 12:00am

    Originally posted by: Shahid Munir

    hi, I am facing a problem. I haven't yet gone into the source code. The problem is that the name of the network appears but the tree does not expand. So i cannot select the target machine. And there is no other way to input the target IP. Please tell me why I am having this problem....
    Shahid

    Reply
  • Cool Stuff

    Posted by Legacy on 04/03/2003 12:00am

    Originally posted by: Arun

    I was searching for this utilityto get my friends machine shut down from my machine... !!!
    

    Reply
  • code in c please..

    Posted by Legacy on 03/27/2003 12:00am

    Originally posted by: seshu

    if you can provide the same with c language i get really happy.

    Reply
  • Not wrok with Windows 98

    Posted by Legacy on 11/29/2002 12:00am

    Originally posted by: Sanjay Swar

    Hi,
    I also write a program for remote shut down of the computer which works fine with NT & 2000 but not working with Windows 98 then i search on the web and i got your program and test it with Windows 98 and this also not working with Windows 98. Can you please tell me what i am doing wrong.

    Thanks

    Sanjay Swar

    Reply
  • shutdown standard dialog

    Posted by Legacy on 10/28/2002 12:00am

    Originally posted by: yael

    I would like to open the shutdown dialog from my c++/MFC
    appliction.
    The dialog I need is the dialog that displayed from the start Menu ->shut down..
    can I??
    thanks yael

    Reply
  • --

    Posted by Legacy on 10/10/2002 12:00am

    Originally posted by: sas

    -

    Reply
  • Invoking A client Side exe

    Posted by Legacy on 08/11/2002 12:00am

    Originally posted by: Rakesh

    Fine code but in the same way how do i call a client side exe from server itself so that it will be executed on the client itself.

    Do help Me.

    Reply
  • Error Network Path"

    Posted by Legacy on 07/02/2002 12:00am

    Originally posted by: Raja Thangavel

    Dear...
    
    

    When i run this program in win2000 if is not getting the machine name.

    and when i run in WINNT it is giving an error as "Network Path was not found"

    Please specify me how to rectify it....

    i need this programm...very urgently..

    Reply
  • I think you must have SE_REMOTE_SHUTDOWN privilage to do it.

    Posted by Legacy on 06/19/2002 12:00am

    Originally posted by: NowCan

    http://vip.6to23.com/NowCan1/tech/netshutd.htm
    have a reference here if you can see it.

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • With 81% of employees using their phones at work, companies have stopped asking: "Is corporate data leaking from personal devices?" and started asking: "How do we effectively prevent corporate data from leaking from personal devices?" The answer has not been simple. ZixOne raises the bar on BYOD security by not allowing email data to reside on the device. In addition, Zix allows employees to maintain complete control of their personal device, therefore satisfying privacy demands of valued employees and the …

  • Live Event Date: August 14, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Data protection has long been considered "overhead" by many organizations in the past, many chalking it up to an insurance policy or an extended warranty you may never use. The realities of today makes data protection a must-have, as we live in a data-driven society -- the digital assets we create, share, and collaborate with others on must be managed and protected for many purposes. Check out this upcoming eSeminar and join Seagate Cloud …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds