gpt4 book ai didi

shell - 如何使用 ShellExecute 在 'config' 模式下运行屏幕保护程序?操作系统覆盖我的 ShellExecute 调用

转载 作者:行者123 更新时间:2023-12-03 19:13:08 25 4
gpt4 key购买 nike

我想使用 ShellExec 在“配置”模式下运行屏幕保护程序。我使用这个 (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。现在发送的参数被操作系统覆盖。收到的参数现在是“/S”。

有趣!

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

最佳答案

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

image

因此,您的 /c 参数将被忽略。

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

image

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. 

Otherwise, run the .scr file with CreateProcess() instead of ShellExecute() so you can specify the /c parameter directly:

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;

关于shell - 如何使用 ShellExecute 在 'config' 模式下运行屏幕保护程序?操作系统覆盖我的 ShellExecute 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46672282/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com