WPF C # - Make Registry Changes on Application Launch for Standard (Non-Rooted) User

Below are the steps I tried to follow for my Windows desktop. Where do I need to write FEATURE_BROWSER_EMULATION

. Which works fine for an administrator, but doesn't work for a regular user who is not allowed to write to the registry.

1) I installed <requestedExecutionLevel level="highestAvailable" uiAccess="false" />

so that the user has rights at the time of installation.

And created a script and ran during install, which was unable to install the app because of this script.

On Error Resume Next
strComputer = "."
Const HKEY_LOCAL_MACHINE = &H80000002
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

Sub strLocalMachinePath1 = "SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION"
objRegistry.OpenSubKey(HKEY_LOCAL_MACHINE, strLocalMachinePath1);

If objRegistry.GetValue("MyApp.exe") Is Nothing Then
    objRegistry.SetValue("MyApp.exe", 8000)
End If
If objRegistry.GetValue("MyApp.vshost.exe") Is Nothing Then
     objRegistry.SetValue("MyApp.vshost.exe", 11000)
End If

End Sub

      

2) I have tried <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

which asks for the admin password every time I open the app. Which fails for a standard user who is not an administrator.

3) I tried to write the same thing in App.xml.cs

App_Startup

key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\Main", true);
            key.CreateSubKey("FeatureControl");
           key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\Main\FeatureControl", true);
            key.CreateSubKey("FEATURE_BROWSER_EMULATION");
           key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true);

      

But it doesn't matter and starts a mistake No Internet connection

var client = new WebClientPool().GetIdleWebClientObject()

      

+3


source to share


1 answer


If the user does not have the rights to write to a specific entry in the registry, he cannot do this, regardless of requestedExecutionLevel

which you specify for your application. When you specify something like requireAdministrator

this, it just means that it will display a UAC prompt on startup to launch the app with administrator privileges, but if the user is not an administrator it won't help.

However, in this case, you do not need this, because instead of writing to, HKEY_LOCAL_MACHINE

you can write FEATURE_BROWSER_EMULATION

to HKEY_CURRENT_USER

part of the registry:



HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION

      

+2


source







All Articles