DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C (http://www.daniweb.com/forums/forum118.html)
-   -   remote system (http://www.daniweb.com/forums/thread29510.html)

wani_raj Aug 1st, 2005 3:51 am
remote system
 
is it possible to write a program which will shutdown the remote systme in c?

Sauce Aug 1st, 2005 5:48 am
Re: remote system
 
Quote:

Originally Posted by wani_raj
is it possible to write a program which will shutdown the remote systme in c?

Of course its possible. Depends on what way you want to do it and if you have access to install an application on the before mentioned "remote system".

Alvein Aug 1st, 2005 5:48 am
Re: remote system
 
Quote:

Originally Posted by wani_raj
is it possible to write a program which will shutdown the remote systme in c?

Please try,

BOOL RemoteShutdown(LPSTR szMachine,LPSTR szMessage,DWORD dwTimeout,BOOL bForce,BOOL bReboot) {
BOOL bRS=FALSE;
HANDLE hToken;
TOKEN_PRIVILEGES tpvPrivileges;
  if(OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&hToken))
    if(LookupPrivilegeValue(NULL,SE_REMOTE_SHUTDOWN_NAME,&(tpvPrivileges.Privileges[0].Luid))) {
      tpvPrivileges.PrivilegeCount=1;
      tpvPrivileges.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;
      if(AdjustTokenPrivileges(hToken,FALSE,&tpvPrivileges,sizeof(TOKEN_PRIVILEGES),NULL,NULL))
        bRS=InitiateSystemShutdown(szMachine,szMessage,dwTimeout,bForce,bReboot);
      }
  return(bRS);
}

Tested locally. I Don't have a network to try a working case.

szMachine: either name or IP should work.
szMessage*: some blah's for remote user to be aware of your action.
dwTimeout*: how many seconds to show your blah's.
bForce: close all applications with no confirmation.
bReboot: follow shutdown with a restart.

*(NULL,0): inmediate shutdown.

RemoteShutdown() returns TRUE on success.


All times are GMT -4. The time now is 1:58 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC