1

Despite what you read, it turns out that a Windows Screen Saver is NOT "just" an .exe renamed to .scr. A .scr file is not "launched" directly, like an EXE. Instead, Windows looks for the executable in the .scr file, and re-launches that executable, with whatever command line parameters Windows wants to feed the executable.

This means that if you create a Shortcut to your .scr file, with your own parameters (for example, "myscreensaver.scr /windowed /doublebuffered"), when you use that shortcut, Environment.CommandLine reveals that what got launched was "myscreensaver.scr /S". Note that my parameters have been replaced.

I understand the role of the /s, /c and /p parameters here. This needs no explanation, and I use them correctly in my screen saver. But I would like my original parameters back, also. Is it possible to get the name of the process that launched my process, and get the command line parameters that were fed to that process?

Cardinal Fang
  • 283
  • 2
  • 12
  • When you create your screen saver you are making a windows form and you rename the exe to scr, so I'm not sure where you're getting `Despite what you read, it turns out that a Windows Screen Saver is not an .exe..`. You are the one creating the screen saver and have control over it. Am I missing something? And to add to this, if you're not installing your screen saver why are you bothering with renaming it to scr AND if you are installing it why are you invoking the scr manually (double click)? By renaming it to scr and installing it you are expecting windows to invoke it. – The Muffin Man Aug 28 '14 at 22:48
  • I'm pretty sure what you need is not possible and you'll need a different way, perhaps a config file. Maybe someone will prove me wrong, though. – vesan Aug 28 '14 at 22:51
  • @vesan To change screen saver settings you use the options form. Those settings are typically saved and loaded to/from the registry. Like I said, if you want to invoke it manually don't make it an scr file. Leave it as an exe. It's simple. – The Muffin Man Aug 28 '14 at 23:07
  • @vesan Thanks for trying to answer the question at hand, Vesan. I suspected as much. :-) Yes, Muffin, you're missing things. When you have to remove the "just" from my quote, you should suspect that you are not actually addressing that quote. I think I was pretty clear about the difference in the statement that followed the quote. – Cardinal Fang Aug 28 '14 at 23:26

1 Answers1

0

You're right about the SCR file. It's just an EXE that Windows launches with /p (preview), /c (configure) or /s (show). The screen saver is responsible for everything else, including saving its settings in the registry or elsewhere.

No, I was not aware that if you launch a screensaver directly that Windows overwrites the command line arguments with /S. Kind of makes sense though.

The command line arguments are stored in a Windows internal buffer that can be accessed from the program or from outside. There is only one buffer, so if it's gone, it's gone.

The process that launched your process is almost certainly Explorer, and if it remembers your command line arguments, it's not telling.

You may be able to find the window for the last application before the shell by looking at the Z order.

All I can think of is that instead of using a shortcut, write your own script that can launch the screen saver (just like a shortcut) but send it some arguments after it launches. That's pretty easy to do.

david.pfx
  • 10,520
  • 3
  • 30
  • 63
  • Sadly, client is pretty specific in requirements: a screensaver that windows will launch, and a desktop shortcut that launches the screensaver with slightly different behavior. Turns out this is not doable. If he won't modify requirements, I think I'll just make the screen saver a stub that launches an my exe (passing the Windows arguments along), and have the shortcut point at the same exe (with its own arguments). – Cardinal Fang Aug 29 '14 at 05:15