-2

I developed a custom screen saver in WPF (with the extension .scr) but I got an issue : When screen saver is run by Windows, the application stop imediately. After some tests, I found that it comes from the fact that I'm creating/writing files.

I tried :

  • to add a manifest to run as administrator
  • name my file with 8 characters + 3 for extension
  • write my file in different location ("C:\", "C:\Windows", "C:\Program Files (x86)",...)

But nothing works...

Any idea ?

Note : I need to write lot of lines in my file

Blacktempel
  • 3,935
  • 3
  • 29
  • 53
Darkerone
  • 51
  • 5
  • 2
    The screensaver cannot write to folders it doesn't have write permissions for. Keep in mind that the screensaver runs under the account of the current desktop user. Choose a directory that is not a restricted directory (for example, you might want your screensaver write to a directory somehwere in the user profile...) Also, make sure to guard all code in your program related to file reading/writing with proper and meaningful exception handling, so you (or your users) actually have a chance to get at least some information about the "why?" when something is going wrong... –  Nov 14 '18 at 22:29
  • It is extremely suspicious behavior. Temporarily disable the installed anti-malware product and try again. – Hans Passant Nov 15 '18 at 10:33
  • @elgonzo If I understand, the screensaver can write a file but only in user profile folders ? I will try this. Exception handling is a good idea, I always forget it. But I will not have logs if I can't write in a file... – Darkerone Nov 15 '18 at 19:19
  • @HansPassant I will try this too – Darkerone Nov 15 '18 at 19:21

1 Answers1

0

Ok, my bad... I found where were my problemss.

First, screen saver does not have permission to write in Windows folder.

Then, I was trying to write in a special folder using Environment.SpecialFolder.MyDocuments but this property return the name of the folder. So I need to use Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) instead.

Finally, I was trying to write a file in a folder that didn't exists. I thought that the folder would be created automatically but I was wrong...

As suggested by @elgonzo, I have added exception handler and displayed the error messages in a message box using MessageBox.Show(log).

Darkerone
  • 51
  • 5