views:

66

answers:

5

Hi,

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

A: 

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

Richard
ProcessMonitor shows everything app is trying to read. ProcessExplorer shows a list of apps in the system.
Andrey Shchekin
Ah yes, I mixed them up, sorry. Should've written: *did you mean Process Monitor from SysInternals, here's the link: http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx*
Abel
A: 

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.

Abel
+1  A: 

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.

Igor Korkhov
How can I make the screensaver read the config file from the directory the .scr file is in?
FrancisCastiglione
@FrancisCastiglione: Sorry for asking you a question instead of answering yours, but how do you read your config now?
Igor Korkhov
A: 

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
0xA3
+1  A: 

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.

FrancisCastiglione