这是关机的代码:
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
BOOL fResult;
//打开与当前进程相关联的存取标识
if (!::OpenProcessToken(GetCurrentProce(),TOKEN_ADJUST_PRIVILEGES
|TOKEN_QUERY,&hToken))
AfxMessageBox("OpenProcessToken failed");
//查出本机系统的当前特权的Luid
::LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&tkp.Privilege[0].Luid);
tkp.PrivilegeCount =1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
::AdjustTokenPrivileges(hToken,FALSE,&tkp,0,(PTOKEN_PRIVILEGES) NULL,0);
if (::GetLastError()!=ERROR_SUCCESS)
AfxMessageBox("AdjustTokenPrivileges enable failed");
fResult = ::InitiateSystemShutdown(NULL,"即将关机",20,FALSE,
TRUE);
if (!fResult)
AfxMessageBox("InitiateSystemShutDown failed");
tkp.Privileges[0].Attributes = 0;
::AdjustTokenPrivileges(hToken,FALSE,&tkp,0,(PTOKEN_PRIVILEGES) NULL,0);
if (::GetLastError()!=ERROR_SUCCESS)
AfxMessageBox("AdjustTokenPrivileges disable failed");
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
BOOL fResult;
//打开与当前进程相关联的存取标识
if (!::OpenProcessToken(GetCurrentProce(),TOKEN_ADJUST_PRIVILEGES
|TOKEN_QUERY,&hToken))
AfxMessageBox("OpenProcessToken failed");
//查出本机系统的当前特权的Luid
::LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&tkp.Privilege[0].Luid);
tkp.PrivilegeCount =1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
::AdjustTokenPrivileges(hToken,FALSE,&tkp,0,(PTOKEN_PRIVILEGES) NULL,0);
if (::GetLastError()!=ERROR_SUCCESS)
AfxMessageBox("AdjustTokenPrivileges enable failed");
fResult = ::InitiateSystemShutdown(NULL,"即将关机",20,FALSE,
TRUE);
if (!fResult)
AfxMessageBox("InitiateSystemShutDown failed");
tkp.Privileges[0].Attributes = 0;
::AdjustTokenPrivileges(hToken,FALSE,&tkp,0,(PTOKEN_PRIVILEGES) NULL,0);
if (::GetLastError()!=ERROR_SUCCESS)
AfxMessageBox("AdjustTokenPrivileges disable failed");
解决方案 »
- media player activex控件
- 为何VC++ 6.0在ClassView中右击非MFC类不显示重载虚函数的菜单?
- oleaut32.dll 出现 access violation reading location 0xffffffff的 错误
- 如何找到头文件rtccore.h
- 不大懂网络,大家帮忙解答下
- 问一个问题,是关于线程同步的,老出现CPU占用率9x
- SetTimer的使用问题
- 如何按扇区读取DVD数据?在线等待
- 大家给推荐一下国外的好的新闻组服务器、网站,来着有分
- *****谁有关于pc机采集数据的驱动程序资料****
- 简单问题:请问如何在点击一个菜单弹出一个对话框时,将对话框中的写的程序启动。(内详!!)(帮帮忙!!)
- 请问如何知道当前文档下文件的路径(在程序的C???View下)
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
MessageBox (NULL, TEXT("OpenProcessToken") , TEXT ("Error"),MB_ICONERROR);
// Get the LUID for the shutdown privilege.
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get the shutdown privilege for this process.
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0);
// Cannot test the return value of AdjustTokenPrivileges.
if (GetLastError() != ERROR_SUCCESS)
MessageBox (NULL, TEXT("AdjustTokenPrivileges") ,
TEXT("Error"),MB_ICONERROR);
// Shut down the system and force all applications to close.
if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF, 0))
MessageBox (NULL, TEXT("ExitWindowsEx") ,
TEXT("Error"),MB_ICONERROR);