會C++大大請進
於
2010/02/21 11:20:23
發文
我要寫一個重起電腦的程式怎麼寫阿?<br>試了好久都失敗<br>
| |||
我要寫一個重起電腦的程式怎麼寫阿? 試了好久都失敗 | |||
寫“請重按電源按鈕” 😆 我自己出去 😰
一業一貫
#include<iostream>
using namespace std;
int main(void)
{
system("shutdown -r");
return 0;
}
這樣就可以了..
XP本身有shutdown指令干嘛還自己寫😵
using namespace std;
int main(void)
{
system("shutdown -r");
return 0;
}
這樣就可以了..
XP本身有shutdown指令干嘛還自己寫😵
~ 真相永遠只有一個 ~
bool SetSuspend(int enumSuspendType)
{
HINSTANCE hPowrprofDll = LoadLibrary(_T("POWRPROF.DLL"));
bool bResult = false;
if(hPowrprofDll)
{
fnSetSuspendState SetSuspendState = (fnSetSuspendState) GetProcAddress(hPowrprofDll, "SetSuspendState");
fnIsPwrSuspendAllowed IsPwrSuspendAllowed = (fnIsPwrSuspendAllowed) GetProcAddress(hPowrprofDll, "IsPwrSuspendAllowed");
fnIsPwrHibernateAllowed IsPwrHibernateAllowed = (fnIsPwrHibernateAllowed) GetProcAddress(hPowrprofDll, "IsPwrHibernateAllowed");
switch(enumSuspendType)
{
case 0: // Goto S3
if(IsPwrSuspendAllowed())
{
if(SetSuspendState (FALSE, FALSE, FALSE))
bResult = true;
}
break;
case 1: // Goto S4
if (IsPwrHibernateAllowed())
{
if(SetSuspendState (TRUE, FALSE, FALSE))
bResult = true;
}
break;
case 2: // Goto S5
{
HANDLE hToken;
HANDLE ProcessHandle = GetCurrentProcess();
TOKEN_PRIVILEGES NewState;
NewState.PrivilegeCount = 1;
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &NewState.Privileges[0].Luid);
NewState.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
OpenProcessToken(ProcessHandle, TOKEN_ALL_ACCESS, &hToken);
AdjustTokenPrivileges(hToken, NULL, &NewState, NULL, NULL, NULL);
if(ExitWindowsEx(EWX_POWEROFF, NULL) > 0)
bResult = true;
}
break;
}
FreeLibrary(hPowrprofDll);
hPowrprofDll = NULL;
}
return bResult;
}
======================================================
睡眠、休眠、關機都給你了
別問我怎麼用😝
{
HINSTANCE hPowrprofDll = LoadLibrary(_T("POWRPROF.DLL"));
bool bResult = false;
if(hPowrprofDll)
{
fnSetSuspendState SetSuspendState = (fnSetSuspendState) GetProcAddress(hPowrprofDll, "SetSuspendState");
fnIsPwrSuspendAllowed IsPwrSuspendAllowed = (fnIsPwrSuspendAllowed) GetProcAddress(hPowrprofDll, "IsPwrSuspendAllowed");
fnIsPwrHibernateAllowed IsPwrHibernateAllowed = (fnIsPwrHibernateAllowed) GetProcAddress(hPowrprofDll, "IsPwrHibernateAllowed");
switch(enumSuspendType)
{
case 0: // Goto S3
if(IsPwrSuspendAllowed())
{
if(SetSuspendState (FALSE, FALSE, FALSE))
bResult = true;
}
break;
case 1: // Goto S4
if (IsPwrHibernateAllowed())
{
if(SetSuspendState (TRUE, FALSE, FALSE))
bResult = true;
}
break;
case 2: // Goto S5
{
HANDLE hToken;
HANDLE ProcessHandle = GetCurrentProcess();
TOKEN_PRIVILEGES NewState;
NewState.PrivilegeCount = 1;
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &NewState.Privileges[0].Luid);
NewState.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
OpenProcessToken(ProcessHandle, TOKEN_ALL_ACCESS, &hToken);
AdjustTokenPrivileges(hToken, NULL, &NewState, NULL, NULL, NULL);
if(ExitWindowsEx(EWX_POWEROFF, NULL) > 0)
bResult = true;
}
break;
}
FreeLibrary(hPowrprofDll);
hPowrprofDll = NULL;
}
return bResult;
}
======================================================
睡眠、休眠、關機都給你了
別問我怎麼用😝
我是優卡好寶寶!
C語言,離偶20年了!!!