在98,NT及2000上重新启动机器

类别:VC语言 点击:0 评论:0 推荐:

如下是源码,其实在98上只用最后一句ExitWindowEx即可,前面是为了取得权限.

TOKEN_PRIVILEGES tkp,tkpNewButIgnored;
  HANDLE hdlTokenHandle;
  LUID tmpLuid;
  BOOL rc;
  DWORD lBufferNeeded;

  HANDLE  hdlProcessHandle = GetCurrentProcess();
  rc = ::OpenProcessToken(hdlProcessHandle,TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,
   &hdlTokenHandle);

  rc = LookupPrivilegeValue("","SeShutdownPrivilege", &tmpLuid);
  tkp.PrivilegeCount = 1; // One privilege to set
  tkp.Privileges[0].Luid = tmpLuid;
  tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  rc = ::AdjustTokenPrivileges(hdlTokenHandle,
   FALSE,
   &tkp,
   sizeof(tkpNewButIgnored),
   &tkpNewButIgnored,
   &lBufferNeeded);

  ExitWindowsEx(EWX_REBOOT,0);

本文地址:http://com.8s8s.com/it/it3318.htm