3
votes

I've written a screen saver in C# but whenever I run it on preview mode or let it kick in, it throws an exception. When I double click it in Windows\System32 it runs fine. With the Visual studio debugger I sussed out that it doesn't read the .config file of the application, which is also in Windows\System32.

I think that when rundll32.exe executes the screen saver, the app.config file is being omitted. Is there a way to force it to load?

Thanks

5
With .NET screen-savers I always used custom serialized myScreenSaver.xml only (at the same time used also for changing sreen-saver settings).sabiland

5 Answers

2
votes

Thanks to those who recommended SysInternals' Process Monitor. Using that, I saw that it's looking for an 8-letter version of the config filename. It's the first six letters of the SCR file then ~1.scr, because that's the name of the process. All I have to do is rename the file or, rather keep 2 versions of it as I don't want to change the name of the scr file.

1
votes

As far as I remember from my previous experience, screen savers run with its "current directory" set to %userprofile%. You may check if it is true or not by temporarily placing your config file into that directory. And if it happens to be true then you have to add code to read your config from the directory in which your screen saver sits, not from its current directory.

0
votes

Use Process Monitor to see what config files the screen saver is trying to read.

0
votes

My guess is that your application is run with a different working directory. From this post (read down) it seems that you need to create you normal executable, rename to *.scr, rightclick the file and select "install" which moves both to the system32 dir.

Perhaps the "install" feature changes the way your screensaver is called or where it should look for as a working dir.

0
votes

If none of the tips so far are working you could as well

  • add your configuration to the machine.config file, or
  • use a custom file for configuration