ExitWindowsEx(EWX_LOGOFF¦EWX_FORCEIFHUNG,0)
解决方案 »
- gdi绘制动态波形,出现闪光的画面。有的时候会出现比较明显烁动,怎么解决
- 结构体里的string成员, 进行ostringstream和istringstream转换后就报错
- vc6.0调用vs2005编译的动态库的问题,当函数参数为CString时,出现连接错误的问题
- 如何按照系统当前设置的时间格式,获得当前的系统时间?
- 为什么int 运行完出错 char就没有错------看看把~~!!!!!!
- 用原始套接口写了一个 sniffer,欢迎大家试用
- 怎样将一个数据集的记录数赋值给edit or label ?
- 想用OPENGL实现人脸的皱眉,请问各位大侠有何高招,望不吝赐教!
- 高分相送!请问如何得到桌面上开始状态条的大小?
- 惨!为什么这个问题无人回答?
- 急
- 请问:CRunTimeClass是干吗用的?
请问:如果在Win2000 or WinXP下,也是用同样的函数吗?
要设置特权级别的。
给你我的代码:
/*
* This function is used to shutdown the destination computer.
* If no computer name is provided, it shutdowns the current system.
*/
bool ShutDown(DWORD mode, LPTSTR lpMachineName){
bool flag = false;
HANDLE tokHandle;
if (OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, & tokHandle))
{
TOKEN_PRIVILEGES priv;
priv.PrivilegeCount = 1;
priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, & priv.Privileges[0].Luid)
& & AdjustTokenPrivileges(tokHandle, FALSE, & priv, NULL, NULL, NULL)
& & (lpMachineName == NULL
? ExitWindowsEx(mode, 0)
: InitiateSystemShutdown(lpMachineName,
NULL,
0,
(mode & EWX_FORCE) != 0,
(mode & EWX_REBOOT) != 0)
)
)
flag = true;
}
return flag;
}