none
Access to Registry and Windows 10 version 1709, RRS feed

  • Question

  • Hello,

    we have an exe written in C# which tries to access some keys under

    HKEY_USERS\.DEFAULT\Software\

    Until Windows 10 version 1703 there wasn't a Problem.

    But after updating to  Windows 10 version 1709, a SecuzrityException is thrown.

    This is the used manifest

    <?xml version="1.0" encoding="utf-8"?>
    <asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
      <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    	  <security>
    		  <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
    			  <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
    		  </requestedPrivileges>
    		  <applicationRequestMinimum>
    			  <defaultAssemblyRequest permissionSetReference="Custom" />
    			  <PermissionSet class="System.Security.PermissionSet" version="1" ID="Custom" SameSite="site" Unrestricted="true" />
    		  </applicationRequestMinimum>
    	  </security>
      </trustInfo>
      
      <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
        <application>
          <!-- A list of all Windows versions that this application is designed to work with. Windows will automatically select the most compatible environment.-->
          <!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node-->
          <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
        </application>
      </compatibility>
      
      <!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
      <!-- <dependency>
        <dependentAssembly>
          <assemblyIdentity
              type="win32"
              name="Microsoft.Windows.Common-Controls"
              version="7.1.0.0"
              processorArchitecture="*"
              publicKeyToken="6595b64144ccf1df"
              language="*"
            />
        </dependentAssembly>
      </dependency>-->
    
    </asmv1:assembly>
    

    The executable itself is called starter.exe.

    How must I change the manifest to avoid this SecuzrityException ?

    tia

      Hendrik Schmieder

    Wednesday, November 15, 2017 2:21 PM

All replies

  • Hello Hendrik,

    How do you access the key under "HKEY_USERS\.DEFAULT\Software\" in C#?  I test the following code under windows 10 which version is 1709 and it works well on my side.

                //set value in registy
                RegistryKey key = Registry.Users;
                RegistryKey software = key.OpenSubKey(".DEFAULT\\Software\\RegisteredApplications", true);
                software.SetValue("TTTTTT","eeeeeeee");
                key.Close();
    
    
                //get value in registy
                RegistryKey key1 = Registry.Users;
                RegistryKey software1 = key.OpenSubKey(".DEFAULT\\Software\\RegisteredApplications", true);
                var value=software1.GetValue("TTTTTT");
                Console.WriteLine(value);
                key1.Close();
    

    My operate system version

    And I also try your manifest in my program and everything is ok. In your manifest you require to run the program under admin privileges. And I have a litter confused that why your not comment "supportedOS node" that indicates your program works with windows 7.

    If you have any issues please feel free to contact me.

    Sincerely,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 16, 2017 6:08 AM
    Moderator
  • Hello,

    we use

    private static RegistryKey OpenKey(RegistryKey basekey, string path)
    {
    	RegistryKey key = basekey.OpenSubKey(path, true);
    	if (key == null)
    	{
    		key = basekey.CreateSubKey(path);
    	}
    	return key;
    }

    with basekey egistry.Users.

    If the executable is started as Administrator, then no exception occurs,

    but if startet as normal user then the Security exceptions occurs.

    We solved the problem by replacing true by false in OpenSubKey.

    regards

      Hendrik Schmieder

     

     

    Thursday, November 16, 2017 3:13 PM
  • Hello Hendrik,

    I'm glad that you've solved the problem, The second parameter of OpenSubKey specifies whether write access is to be applied to the key. This is a good tips for us.  And you could mark your reply as answer, This can be beneficial to other community members reading this thread. Thanks a lot.

    Sincerely,

    Fei Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 17, 2017 7:47 AM
    Moderator