开发者

Screen saver application doesn't read App.Config

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 re开发者_Go百科ad 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


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.


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.


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


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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜