3

How to install (register) screensaver programmatically?

Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
user626528
  • 13,999
  • 30
  • 78
  • 146

2 Answers2

5

AFAIk there are two ways:

  1. Permanent registration by copying it to a location that windows searches, such as System32. But don't hardcode "C:\Windows\System32". You need to query the system to find out where the system directory is.
  2. Calling the Install action on the .scr file, which results in temporary activation. But the screensaver will disappear once another has been selected and the dialog restarted.

But this is from Win95 times, so it's possibly outdated.


I see three ways to call install:

  1. ShellExecute(Ex) using the install verb
  2. Call rundll32.exe desk.cpl,InstallScreenSaver %l
  3. Load desk.cpl as library(LoadLibrary or by declaring an import for InstallScreenSaver) and then call the InstallScreenSaver method with your own path as parameter.
CodesInChaos
  • 106,488
  • 23
  • 218
  • 262
  • 2
    Probably not outdated I suspect! – David Heffernan Mar 12 '11 at 12:33
  • 1
    How to call "install" action programmatically? – user626528 Mar 13 '11 at 08:55
  • @user added some ideas on that – CodesInChaos Mar 13 '11 at 09:48
  • The problem with the desk.cpl method is that it opens a configuration dialog. Not good if you are in an installer. I cannot seem to get 'install' to work in XP but maybe I'm doing it wrong. The only thing that works consistently for me is to right click on the file and select 'install' from the menu but this is not programmatic. Still looking for a proper solution. – jcoffland Oct 24 '12 at 23:33
  • @jcoffland Since the installation with that method is temporary, I recommend copying the screensaver to a directory where windows finds it. But the last time I touched screensavers was back on Win95, so I don't remember most details, and the recommended method might have changed since then too. – CodesInChaos Oct 25 '12 at 08:33
  • @user626528 You can create a `ProcessStartInfo` object and set the `Verb` property on it to "Install", then use it in `Process.Start()` – Owen Johnson Mar 25 '13 at 16:24
1

A walkthrough here -

http://www.desktopmanagementsoftware.org/creating-an-msi-package-for-a-screensaver

Miles
  • 11
  • 1