WeG*_*ars 1 delphi shell command-line shellexecute screensaver
我想用ShellExec在'config'模式下运行一个屏幕保护程序.我用这个(Delphi)调用:
i:= ShellExecute(0, 'open', PChar('c:\temp\test.scr'), PChar('/c'), NIL, SW_SHOWNORMAL)
Run Code Online (Sandbox Code Playgroud)
但是,SCR文件接收的参数是'/ S',因此在路上的某个地方,Windows拦截我的呼叫并用'/ S'替换我的参数.
更新
我做了一个实验:
我构建了一个显示参数的应用程序(mytest.exe).我用/ c作为参数启动了mytest.exe.正确接收/ c参数.
然后我将mytest.exe重命名为mytest.scr.现在,操作系统会覆盖发送的参数.收到的参数现在是'/ S'.
有趣!
脏修复:执行以/ c模式执行屏幕保护程序的CMD文件有效!
如果查看注册表,您将看到注册open了.SCR文件扩展名的动词/S,默认情况下使用参数调用该文件:
因此,您的/c参数将被忽略.
如果要调用.scr文件的配置屏幕,请使用config动词而不是open:
ShellExecute(0, 'config', PChar('c:\temp\test.scr'), nil, nil, SW_SHOWNORMAL);
Run Code Online (Sandbox Code Playgroud)
根据.scr文档,运行没有任何参数的文件类似于使用/c参数运行它,只是没有前台模态:
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;
Run Code Online (Sandbox Code Playgroud)