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

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


If you look in the Registry, you will see that the open verb for the .SCR file extension is registered to invoke the file with the /S parameter by default:

image

So, your /c parameter is ignored.

If you want to invoke the configuration screen of a .scr file, use the config verb instead of open:

image

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

Running a .scr file without any parameters is similar to running it with the /c parameter, just without foreground modality, per the documentation:

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;