如何禁用启动某些应用程序?

时间:2013-05-23 12:37:09

标签: delphi delphi-xe2 delphi-2010

有没有办法阻止某些应用程序启动

1)例如:我不希望用户启动notepad.exe:可能吗?

2)除了“notepad.exe”之外,是否可以禁止启动所有应用程序?

由于

1 个答案:

答案 0 :(得分:1)

方法可能是

procedure KillProcess(hWindowHandle: HWND);
var
  hprocessID: INTEGER;
  processHandle: THandle;
  DWResult: DWORD;
begin
  SendMessageTimeout(hWindowHandle, WM_CLOSE, 0, 0,
    SMTO_ABORTIFHUNG or SMTO_NORMAL, 5000, DWResult);

  if isWindow(hWindowHandle) then
  begin
    // PostMessage(hWindowHandle, WM_QUIT, 0, 0);

    { Get the process identifier for the window}
    GetWindowThreadProcessID(hWindowHandle, @hprocessID);
    if hprocessID <> 0 then
    begin
      { Get the process handle }
      processHandle := OpenProcess(PROCESS_TERMINATE or PROCESS_QUERY_INFORMATION,
        False, hprocessID);
      if processHandle <> 0 then
      begin
        { Terminate the process }
        TerminateProcess(processHandle, 0);
        CloseHandle(ProcessHandle);
      end;
    end;
  end;
end;

你有一个计时器,线程或你想要的过程。执行

KillProcess(FindWindow('notepad',nil));