主页:http://www.maxss.net
邮件:maxchou@163.com
用过FlashGet的人应该都知道,在FlashGet中有一个下载完成后关闭计算机的功能,这种功能是如何实现的呢?其实通过调用一个Windows API函数ExitWindowsEx()就可以完成。但在Windows 98和Windows 2000实现稍有不同,下面将会续个进行介绍。
ExitWindowsEx()函数定义格式:
BOOL ExitWindowsEx( UINT uFlags, // shutdown operation DWORD dwReason // shutdown reason ); |
在Windows 98实现“注销/重启/关机”功能代码:
ExitWindowsEx(EWX_LOGOFF, 0); // 注销 ExitWindowsEx(EWX_REBOOT, 0); // 重启 ExitWindowsEx(EWX_SHUTDOWN, 0); // 关机 |
在Windows 2000实现“注销/重启/关机”功能代码:
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
if (FForce) // Forces processes to terminate
FFlag |= EWX_FORCE;
// Get version info to determine operation
OSVERSIONINFO osvi;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (GetVersionEx(&osvi) == 0)
return false;
// Determine the platform
if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
// Windows NT 3.51, Windows NT 4.0, Windows 2000,
// Windows XP, or Windows .NET Server
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return false;
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
}
ExitWindowsEx(FFlag, 0); |
未明确核心内容的博客
博客仅提供了主页地址http://www.maxss.net和邮件地址maxchou@163.com,未包含信息技术相关关键信息。
571

被折叠的 条评论
为什么被折叠?



