我也提过类似问题,下一段代码是C++ Builder,希望对你有所帮助:
void __fastcall Tfrminst::BtfshClick(TObject *Sender)
{
if(RadRest->ItemIndex==0){
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// SE_SHUTDOWN_NAME must be enabled
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
&hToken))
{
}//return FALSE;
//Get a LUID for SE_SHUTDOWN_NAME privilege
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
// PrivilegeCount enables more than one privilege to be set at a //time.
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Some privileges are initially disable, so each process must //adjust
// the privilege by calling AdjustTokenPrivilege
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, 0);
ExitWindowsEx(EWX_REBOOT,0);
}
Close();
mainfrm->Close();
}