Hi,
muss es eine MFC Funktion sein, oder darf ich dir mit einer Windows API helfen?
Variante 1:
bool ShutdownSystem(unsigned int uFlags)
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
bool bOkShutdown;
OSVERSIONINFO osv;
const char szShutdown[] = "SeShutdownPrivilege";
osv.dwOSVersionInfoSize=sizeof(osv);
GetVersionEx(&osv);
if(osv.dwPlatformId==VER_PLATFORM_WIN32_NT) {
if(OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hToken) ) {
LookupPrivilegeValue("",szShutdown, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
bOkShutdown = (AdjustTokenPrivileges(hToken,0,&tkp,0,(PTOKEN_PRIVILEGES)NULL,0)!=0);
}
}
else {
bOkShutdown=true;
}
if(bOkShutdown) {
return (ExitWindowsEx(uFlags,0)!=0);
}
return false;
}
Variante 2:
#include windows.h
#include iostream.h
void main()
{
int x;
cout<<"1 to shutdown"<<endl,
<<"2 to restart"<<endl,
<<"3 to logoff"<<endl<<endl;
do
{
cout<<"what would you like to do: ";
cin>>x;
}while((x <=0) || (x >= 2))
if(x==1)
{
ExitWindows(EWX_SHUTDOWN,0);//shutdown command
}
if(x==2)
{
ExitWindows(EWX_REBOOT,0);//restart command
}
if(x==3)
{
ExitWindows(EWX_LOGOFF,0);//log off command
}
}
Gruß
Toaster