WIN98和WIN2000的关机有什么不同,WIN2000如何实现关机? WIN98和WIN2000的关机有什么不同,WIN2000如何实现关机? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用ExitWindowsEx();这个函数msdn上在win2k下关机的一段例子HANDLE hToken; TOKEN_PRIVILEGES tkp; // Get a token for this process. if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) error("OpenProcessToken"); // 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) error("AdjustTokenPrivileges"); // Shut down the system and force all applications to close. if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) error("ExitWindowsEx"); 这个函数win98也支持 但是传参数的时候一些宏定义的作用和在w2k下就不一样了具体可以看看msdn这段代码在win2k下没问题 win98就不知道了 没装 . if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) error("OpenProcessToken"); // 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) error("AdjustTokenPrivileges"); // Shut down the system and force all applications to close. 我的MSDN怎么找不到这些呢?是不是我的MSDN不行,还是你说的不是真的 ExitWindowsEx();是吗?一个最简短的关机的程序怎么写? OSVERSIONINFO osv;osv.dwOSVersionInfoSize=sizeof OSVERSIONINFO;GetVersionEx(&osv);if(osv.dwPlatformId==VER_PLATFORM_WIN32_NT){ HANDLE hProcess,hToken; TOKEN_PRIVILEGES Privileges; LUID luid; hProcess=GetCurrentProcess(); OpenProcessToken(hProcess,TOKEN_ADJUST_PRIVILEGES,&hToken); Privileges.PrivilegeCount=1; LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&luid); Privileges.Privileges[0].Luid=luid; Privileges.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED; AdjustTokenPrivileges(hToken,FALSE,&Privileges,NULL,NULL,NULL);}ExitWindowsEx(EWX_POWEROFF|EWX_SHUTDOWN|EWX_FORCE,0); 关机前当前进程要先获得一个关机权限你在msdn 2001或者2003中的Index中找ExitWindowsEx()这个函数 其中有一个连接就是我贴的那段代码 今天可用分涨到50多万,散分 关于将大型文本文件转化成数据库文件的效率问题 包含出错 在c++程序中怎么连接*.obj文件? CString str="aaa\nbbb"; edit.SetWindowText(str); 为什么显示出的文本不换行? 如何在驱动程序中建立socket? ◆现在大家都使用什么测试管理软件?◆ 请高手相助,gethostname得到的机器名不正确,但用gethostbyname能得到正确IP???? C++ Primer 3/e英文版哪有买!见者有分! 谁能告诉我ASSERT()是什么? 求大家了,一定要帮忙,肯定给分,一个非常简单的问题 自解压文件
msdn上在win2k下关机的一段例子
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
error("OpenProcessToken");
// 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)
error("AdjustTokenPrivileges");
// Shut down the system and force all applications to close.
if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
error("ExitWindowsEx");
这个函数win98也支持 但是传参数的时候一些宏定义的作用和在w2k下就不一样了
具体可以看看msdn
这段代码在win2k下没问题 win98就不知道了 没装 .
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
error("OpenProcessToken");
// 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)
error("AdjustTokenPrivileges");
// Shut down the system and force all applications to close. 我的MSDN怎么找不到这些呢?是不是我的MSDN不行,还是你说的不是真的
是吗?
一个最简短的关机的程序怎么写?
osv.dwOSVersionInfoSize=sizeof OSVERSIONINFO;
GetVersionEx(&osv);if(osv.dwPlatformId==VER_PLATFORM_WIN32_NT)
{
HANDLE hProcess,hToken;
TOKEN_PRIVILEGES Privileges;
LUID luid;
hProcess=GetCurrentProcess();
OpenProcessToken(hProcess,TOKEN_ADJUST_PRIVILEGES,&hToken);
Privileges.PrivilegeCount=1;
LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&luid);
Privileges.Privileges[0].Luid=luid;
Privileges.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken,FALSE,&Privileges,NULL,NULL,NULL);
}
ExitWindowsEx(EWX_POWEROFF|EWX_SHUTDOWN|EWX_FORCE,0);
你在msdn 2001或者2003中的Index中找ExitWindowsEx()这个函数 其中有一个连接就是我贴的那段代码