007
25.01.2005, 14:41 Uhr
enno-tyrant
Frag nicht!
|
du kanst natürlich auch dein eigenes shutdown schreiben:
Code: |
#include <windows.h>
BOOL SetCurrentPrivilege( LPCTSTR Privilege, BOOL bEnablePrivilege );
int main( int argc, char * argv[] ) { int timeout = 0,force = 1,reboot = 1;//Sekunden,Schnelles Booten,Neustart
{ ( SetCurrentPrivilege( SE_SHUTDOWN_NAME, TRUE ) ); }
{ InitiateSystemShutdown( NULL,NULL, (DWORD) timeout, force, reboot ); }
return 0; }
BOOL SetCurrentPrivilege( LPCTSTR Privilege, BOOL bEnablePrivilege ) { HANDLE hToken; LUID luid; TOKEN_PRIVILEGES tp, tpPrevious; DWORD cbPrevious = sizeof( TOKEN_PRIVILEGES ); BOOL bSuccess = FALSE;
if ( ! LookupPrivilegeValue( NULL, Privilege, &luid ) ) return FALSE;
if( ! OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &hToken ) ) return FALSE;
tp.PrivilegeCount = 1; tp.Privileges[0].Luid = luid; tp.Privileges[0].Attributes = 0;
AdjustTokenPrivileges( hToken, FALSE, &tp, sizeof( TOKEN_PRIVILEGES ), &tpPrevious, &cbPrevious );
if ( GetLastError() == ERROR_SUCCESS ) { tpPrevious.PrivilegeCount = 1; tpPrevious.Privileges[0].Luid = luid;
if ( bEnablePrivilege ) tpPrevious.Privileges[0].Attributes |= ( SE_PRIVILEGE_ENABLED ); else tpPrevious.Privileges[0].Attributes &= ~( SE_PRIVILEGE_ENABLED );
AdjustTokenPrivileges( hToken, FALSE, &tpPrevious, cbPrevious, NULL, NULL );
if ( GetLastError() == ERROR_SUCCESS ) bSuccess=TRUE; }
CloseHandle( hToken ); return bSuccess; }
|
den code habe ich im netz gefunden -- ...um etwas zu verstehen muß man wissen wie es funktioniert... |