Серж
Гость
|
|
« Ответ #2 : 02-12-2004 08:41 » |
|
Dr.Snipper, извини, но текст на С, переделка несложна.
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; }
if (!SetCurrentPrivilege( SE_SHUTDOWN_NAME, TRUE ) ) { ::MessageBox(0,"Недостаточно привилегий!","",MB_OK); }
ExitWindowsEx(EWX_POWEROFF,0);
|