在WINDOWS2000中如何调用函数使其关机AND重新启动!

abc 2000-03-28 01:20:00
...全文
184 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Kenny 2000-05-22
  • 打赏
  • 举报
回复
你需取得授权。这是我的一段源程序:
OSVERSIONINFO oi;
oi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&oi);
if (oi.dwPlatformId == VER_PLATFORM_WIN32_NT)
//if ((ver & 0x0000ffff) == ver and and (ver & 0x0000ffff) == 5)
{
HANDLE handle;
TOKEN_PRIVILEGES tkp;

OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES and TOKEN_QUERY, &handle);
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);

tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

AdjustTokenPrivileges(handle, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
}
::ExitWindowsEx(flag, 0);

注:其中的flag是我在前边定义的,根据选选择是重起机还是关机设定。这段程序可在NT和2000下运行。
Benni 2000-05-22
  • 打赏
  • 举报
回复
Win2000关机与WIN NT4.0关机应该是一致的因为Win2000其实是Win NT5.0。具体方法可以参见《新潮电子》第四期的文章《VC++实现退出Win NT》
tjuwx 2000-05-22
  • 打赏
  • 举报
回复
查一下<<windows API>>
abc 2000-05-18
  • 打赏
  • 举报
回复
最好有一段通过的code!
LJN 2000-05-18
  • 打赏
  • 举报
回复
在W2K中关机会失败,原因是应用程序权限不够。我想只有设法改变权限才行。
查查以Access开头的API吧。

haihong 2000-03-28
  • 打赏
  • 举报
回复

BOOL ExitWindowsEx(
UINT uFlags, // shutdown operation
DWORD dwReserved // reserved
);


uFlags
Specifies the type of shutdown. This parameter must include one of the following values: Value Meaning
EWX_LOGOFF Shuts down all processes running in the security context of the process that called the ExitWindowsEx function. Then it logs the user off.
EWX_POWEROFF Shuts down the system and turns off the power. The system must support the power-off feature.
Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section.

EWX_REBOOT Shuts down the system and then restarts the system.
Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section.

EWX_SHUTDOWN Shuts down the system to a point at which it is safe to turn off the power. All file buffers have been flushed to disk, and all running processes have stopped.
Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section.



This parameter can optionally include the following values: Value Meaning
EWX_FORCE Forces processes to terminate. When this flag is set, the system does not send the WM_QUERYENDSESSION and WM_ENDSESSION messages. This can cause the applications to lose data. Therefore, you should only use this flag in an emergency.
EWX_FORCEIFHUNG Windows NT 5.0 and later: Forces processes to terminate if they do not respond to the WM_QUERYENDSESSION or WM_ENDSESSION message. This flag is ignored if EWX_FORCE is used.



abc 2000-03-28
  • 打赏
  • 举报
回复
具体一点
repus 2000-03-28
  • 打赏
  • 举报
回复
Windows 2000还是WIN32,还是用ExitWindowsEx。

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧