如何使用 ShellExecute 在 'config' 模式下 运行 屏保? OS 覆盖我的 ShellExecute 调用

How to run a screensaver in 'config' mode with ShellExecute? OS overrides my ShellExecute call

我想 运行 使用 ShellExec 在 'config' 模式下创建屏幕保护程序。我用这个 (Delphi) 调用:

 i:= ShellExecute(0, 'open', PChar('c:\temp\test.scr'), PChar('/c'), NIL, SW_SHOWNORMAL)

但是SCR文件接收到的参数是'/S',所以在路上的某个地方Windows拦截了我的电话并将我的参数替换为'/S'。


更新
我做了一个实验:
我构建了一个显示参数的应用程序 (mytest.exe)。我以 /c 作为参数开始 mytest.exe。 /c参数接收正确。
然后我将 mytest.exe 重命名为 mytest.scr。现在发送的参数被 OS 覆盖。收到的参数现在是“/S”。

有趣!

脏修复:在 /c 模式下执行屏幕保护程序的 CMD 文件有效!

如果您查看注册表,您会看到 .SCR 文件扩展名的 open 动词默认注册为使用 /S 参数调用文件:

所以,您的 /c 参数被忽略了。

如果要调用 .scr 文件的配置屏幕,请使用 config 动词而不是 open:

ShellExecute(0, 'config', PChar('c:\temp\test.scr'), nil, nil, SW_SHOWNORMAL);

运行 没有任何参数的 .scr 文件类似于 运行 使用 /c 参数,只是没有前景模态,根据文档:

INFO: Screen Saver Command Line Arguments

   ScreenSaver           - Show the Settings dialog box.
   ScreenSaver /c        - Show the Settings dialog box, modal to the
                           foreground window.
   ScreenSaver /p <HWND> - Preview Screen Saver as child of window <HWND>.
   ScreenSaver /s        - Run the Screen Saver. 

否则,运行 .scr 文件使用 CreateProcess() 而不是 ShellExecute(),因此您可以直接指定 /c 参数:

var
  Cmd: string;
  SI: TStartupInfo;
  PI: TProcessInformation;
begin
  Cmd := 'c:\temp\test.scr /c';
  UniqueString(Cmd);

  ZeroMemory(@SI, SizeOf(SI));
  SI.cb := SizeOf(SI);
  SI.dwFlags := STARTF_USESHOWWINDOW;
  SI.wShowWindow := SW_SHOWNORMAL;

  if CreateProcess(nil, PChar(Cmd), nil, nil, False, 0, nil, nil, SI, PI) then
  begin
    CloseHandle(PI.hThread);
    CloseHandle(PI.hProcess);
  end;
end;