Search code examples
c#wpfwindows-installer

MSI installer All User : Set value for SCRNSAVE.EXE


On my WPF program with MSI Installer, i need to set up HKCU\SCRNSAVE.EXE (and also ScreenSaveTimeOut, ScreenSaveActive and ScreenSaverIsSecure) registry key.

The problem is when i try to insert all this keys on registry via my MSI installer project (set to ALL User), my installer not create the keys.

I already try to install this key on HKLM but the configuration not apply on Windows.

Does there is a way to do this ?

Thank you :)


Solution

  • Found a solution !

    I loop into HKEY_USERS to add my registry key as i needed :)

    RegistryKey lUsersKey = RegistryKey.OpenBaseKey(RegistryHive.Users, RegistryView.Registry64);
    
    foreach (string lUsersSubKey in lUsersKey.GetSubKeyNames())
    {
        try
        {
            RegistryKey lDesktopKey = lUsersKey.OpenSubKey(lUsersSubKey, true).CreateSubKey("Control Panel\\Desktop", true);
            lDesktopKey.SetValue("SCRNSAVE.EXE", myScrPath);
        }
        catch
        {
            continue;
        }
    }