CefSharp browser not working as WPF screensaver on login screen

1

WPF screensaver that uses CefSharp fails in login screen

I wanted to create a WPF screensaver that uses CefSharp to display a website. I installed the screensaver and made all necessary changes in the registry with InnoSetup. The changes are as follows:

[Registry]
Root:HKU; Subkey:".DEFAULT\Control Panel\Desktop"; ValueType: string; ValueName: "SCRNSAVE.EXE"; ValueData:"{app}\{#MyAppExeName}"; Components: login both
Root:HKU; Subkey:".DEFAULT\Control Panel\Desktop"; ValueType: string; ValueName: "ScreenSaveTimeOut"; ValueData:"30"; Components: login both
Root:HKU; Subkey:".DEFAULT\Control Panel\Desktop"; ValueType: string; ValueName: "ScreenSaverIsSecure" ; ValueData:"0"; Components: login both
Root:HKU; Subkey:".DEFAULT\Control Panel\Desktop"; ValueType: string; ValueName: "ScreenSaveActive"; ValueData:"1"; Components: login both
Root:HKCU; Subkey:"Control Panel\Desktop"; ValueType: string; ValueName: "SCRNSAVE.EXE"; ValueData:"{app}\{#MyAppExeName}"; Components: desktop both
Root:HKCU; Subkey:"Control Panel\Desktop"; ValueType: string; ValueName: "ScreenSaveTimeOut"; ValueData:"30"; Components: desktop both
Root:HKCU; Subkey:"Control Panel\Desktop"; ValueType: string; ValueName: "ScreenSaverIsSecure" ; ValueData:"0"; Components: desktop both
Root:HKCU; Subkey:"Control Panel\Desktop"; ValueType: string; ValueName: "ScreenSaveActive"; ValueData:"1"; Components: desktop both

The provided code is part of a .iss file. My Problem is, the screensaver works fine on my Desktop and in my lock screen. In the login screen however, it starts and then fails with the following two codes:

.NET Runtime version 4.0.30319.0 - There was a failure initializing profiling API attach infrastructure. This process will not allow a profiler to attach. HRESULT: 0x80004005. Process ID (decimal): 11004. Message ID: [0x2509].

Application: ScreensaverWPF.scr Framework version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception information: exception code e0000008, exception address 00007FF9668F3E49

The codes are from the Event viewer.

I didn't add try catch statements yet. However, I tried to save .dmp files that WerFault.exe would normally create. WerFault.exe saves the .dmp files from a little script, that crashes intentionally, but doesn't create any for the screensaver. In the registry, I created a key named: Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\ScreensaverWPF.scr

I configured the key as it is descriped in: Collecting User-Mode Dumps

How can I solve this?

Here is my code:

using System;
using System.Windows;
using System.Windows.Input;
using CefSharp;
using CefSharp.Wpf;


namespace ScreensaverWPF
{
    public partial class MainWindow : Window
    {


        private Point mousePoint;
        private string link;

        public void InitializeChromium()
        {
            if (!Cef.IsInitialized)
            {
                CefSettings settings = new CefSettings();
                Cef.Initialize(settings);
                browser = new ChromiumWebBrowser();
            }
        }

        public MainWindow()
        {
            InitializeComponent();
            InitializeChromium();
        }


        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            link = "https://www.google.de/";
            WindowState = WindowState.Maximized;
            Mouse.OverrideCursor = Cursors.None;
            browser.Load(link);
        }

        private void MainWindowKeyDown(object sender, KeyEventArgs e)
        {
            Application.Current.Shutdown();
        }

        private void MainWindowMouseDown(object sender, MouseButtonEventArgs e)
        {
            Application.Current.Shutdown();
        }

        private void MainWindow_OnMouseMove(object sender, MouseEventArgs e)
        {
            Point startPoint = new Point(0,0);
            Point currenPoint = e.GetPosition(overlay);
            if (!mousePoint.Equals(startPoint))
            {
                if (Math.Abs(mousePoint.X - currenPoint.X) > 5 || Math.Abs(mousePoint.Y - currenPoint.Y) > 5)
                {
                    Application.Current.Shutdown();
                }
            }
            mousePoint = currenPoint;
        }

        private void MainWindow_OnMouseWheel_(object sender, MouseWheelEventArgs e)
        {
            Application.Current.Shutdown();
        }
    }
}
.net
wpf
inno-setup
cefsharp
asked on Stack Overflow Nov 19, 2020 by Lukas Benner • edited Nov 20, 2020 by Lukas Benner

1 Answer

1

How can I solve this?

It seems like you need more information first, as you don't know what causes that problem.

CEF will write a file called debug.log. Unfortunately, in session 0 (the login screen), this file is attepted to be written in C:\Windows\System32\debug.log, which is inaccessible.

As a workaround you can create that file with an editor running in administrator mode. Make sure to use a 64 Bit application that is not virtualized (otherwise the file will be created in C:\Windows\SysWOW64\debug.log.

Once the file is created, change the permissions in a way that NT AUTHORITY\LOCAL SERVICE can access it. I just granted everybody full rights like this:

Everybody permissions

Now, log out and let your screen saver run once more. Once the error message is displayed, close it and log in again. Have a look at the debug.log. Likely it will contain an error like this:

[1123/211039.508:ERROR:core_audio_util_win.cc(427)] Failed to create Core Audio device enumerator on thread with ID 10016

I thought this could be mitigated by turning the audio off with

CefSettings settings = new CefSettings();
settings.CefCommandLineArgs.Add("mute-audio", "true");
Cef.Initialize(settings);

but unfortunately that didn't help.

Don't forget to delete debug.log after you found and fixed the issues.

answered on Stack Overflow Nov 24, 2020 by Thomas Weller

User contributions licensed under CC BY-SA 3.0