用ExitWindowsEx(...LOGOFF+...SHUNDOWN+...FORCE)不可以关机。原因是没有得到权限。怎样使用AdjustTokenProcess().
用系统的哪个.dll文件?是用advapi32.dll吗?怎么写代码?望高手指教

解决方案 »

  1.   

    //--重启动
          if Win32Platform <> VER_PLATFORM_WIN32_NT then //不是NT
            ExitWindowsEx(EWX_REBOOT, 0)
          else
          begin
               SetPrivilege('SeShutdownPrivilege', True);
                 if not ExitWindowsEx(EWX_REBOOT + EWX_FORCE, 0) then
                   SetPrivilege('SeShutdownPrivilege', False);
          end;
         //--关机
          if Win32Platform <> VER_PLATFORM_WIN32_NT then //不是NT
            ShellExecute(handle, 'open', 'RUNDLL32.EXE', 'user.exe,ExitWindows', nil, SW_ShowNormal)
          else
          begin
               SetPrivilege('SeShutdownPrivilege', True);
                 if not ExitWindowsEx(EWX_SHUTDOWN + EWX_FORCE+EWX_POWEROFF, 0) then
                   SetPrivilege('SeShutdownPrivilege', False);
          end;