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()这个函数 其中有一个连接就是我贴的那段代码 弹出之对话框后无法对父对话框操作 ocx控件开发入门 使用sscanf函数给浮点数赋值时出现内存访问冲突 提示是指针错误 有写过二维矢量绘图的人,请帮忙。 如何保证Edit Box控件数据输入的合法性? 请教一个edit控件汉字输入的问题 怎么将一个文本框的内容存在一个int变量里? 如何在文本框中显示多行文本。 菜鸟的问题(急、急) 送分小问题:如何将字符串转换成对应的16进制的数字,如“3004”转换成0x3004 求大家了,一定要帮忙,肯定给分,一个非常简单的问题 自解压文件
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()这个函数 其中有一个连接就是我贴的那段代码