我要的锁屏和关机是在当前有大型游戏正在运行的前提下实现的。
   
我要的是类似网吧管理软件那样的效果?锁屏后再进入,程序(游戏)没有出现异常。关机时不能因为某个程序不允许马上关机而不能关机。麻烦了

解决方案 »

  1.   

    利用ShellExecute执行一个scf文件,内容为:
    [Shell]
    Command=2
    IconFile=explorer.exe,3[Taskbar]
    Command=ToggleDesktop这样可以返回到桌面。然后封锁热键,将你的程序设为最前面并且最大化并且BorderStyle=bsNone,这样就实现了锁屏。
    关机则使用ExitWindowsEx这个API
      

  2.   

    ExitWindowsEx参数第一个设EWX_FORCE进行强制关机,如果是在NT下面,则不可以。NT基于安全性考虑,必须先以AdjustTokenPrivileges设置安全层级,才能够关机。
      

  3.   

    SystemParametersInfo(SPI_SCREENSAVERRUNNING,TRUE,nil,0);
    锁定热键
    SystemParametersInfo(SPI_SCREENSAVERRUNNING,FALSE,nil,0);
    取消锁定。根据测试,在XP/2k/nt下面不能用。
      

  4.   

    制做屏幕保护的方法我没有试过。
    锁定热键的方法我倒是用了。
    但是,如果当前有大型游戏正在运行,就会出现问题。
    蓝屏啦、错误信息、死机这些情况都有。
    我的系统的WinMe.关机时也差不多有这种情况。
      

  5.   

    声明系统快照所用到的API的文件在 Delph\Source\Rtl\Win\TlHelp32.pas里。CreateToolhelp32Snapshot
    Process32First
    Process32Next
      

  6.   

    关机这个:使用时PowerOff(True)强制关闭Windows
    procedure TAPIMisc.PowerOff(Force:boolean=false);
    var
      hToken       : THandle;
      tkp          : TTokenPrivileges;
      tkpo         : TTokenPrivileges;
      zero         : DWORD;
    begin
      if Win32Platform=VER_PLATFORM_WIN32_NT then // we've got to do a whole buch of things
         begin  
            zero := 0;
            if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then
               begin
                 MessageBox( 0, 'PowerOff Error', 'OpenProcessToken() Failed', MB_OK );
                 Exit;
               end; // if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken)
            if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then
               begin
                 MessageBox( 0, 'PowerOff Error', 'OpenProcessToken() Failed', MB_OK );
                 Exit;
               end; // if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken)
            // SE_SHUTDOWN_NAME
            if not LookupPrivilegeValue( nil, 'SeShutdownPrivilege' , tkp.Privileges[ 0 ].Luid ) then
               begin
                  MessageBox( 0, 'PowerOff Error', 'LookupPrivilegeValue() Failed', MB_OK );
                  Exit;
               end; // if not LookupPrivilegeValue( nil, 'SeShutdownPrivilege' , tkp.Privileges[0].Luid )
            tkp.PrivilegeCount := 1;
            tkp.Privileges[ 0 ].Attributes := SE_PRIVILEGE_ENABLED;        AdjustTokenPrivileges( hToken, False, tkp, SizeOf( TTokenPrivileges ), tkpo, zero );
            if Boolean( GetLastError() ) then
               begin
                  MessageBox( 0, 'PowerOff Error', 'AdjustTokenPrivileges() Failed', MB_OK );
                  Exit;
               end // if Boolean( GetLastError() )
            else if Force then ExitWindowsEx( EWX_Force or EWX_POWEROFF, 0 )
                          else ExitWindowsEx( EWX_POWEROFF, 0 );
          end // if OSVersion = 'Windows NT'
       else // just shut the machine down
            if Force then ExitWindowsEx( EWX_Force or EWX_POWEROFF, 0 )
                          else ExitWindowsEx( EWX_POWEROFF, 0 );
    end;
      

  7.   

    能否不锁屏,而锁住键盘和鼠标,即禁止输入。同时跳出对话框。我想这个能实现吧。
    锁键盘和鼠标:
    // Import BlockInput function form user32.dll: // BlockInput Funktion von user32.dll importieren: function BlockInput (fBlockInput : boolean) : DWord; stdcall; external 'user32.DLL'; {block input/ blockieren} procedure TForm1.Button1Click(Sender: TObject); 
    begin 
     BlockInput(true); 
    end; {unblock input / Blockierung aufheben} procedure TForm1.Button2Click(Sender: TObject); 
    begin 
     BlockInput(false); 
    end;