locked
HKEY_CLASSES_ROOT create key permissions RRS feed

  • Question

  • Hello all,

    I'm stuck with my program on the task of associating a new file type (a new file extension) to my program.
    I've serched the Internet and found out the key you need to write in the registry to setup a new file association but it seems that my program can't write to the registry.
    I'm running Windows Vista with UAC enabled (I need to test the default configuration as Vista comes with UAC enabled by default) and I quite clearly understand that there are restrictions to HK_CLASSES_ROOT key modification.
    In fact every attemp I've done to create these key programmatically has failed with an "UnauthorizedAccessException"

    My question is: is there a way my program can gain enough authorization to write to the HK_CLASSES_ROOT key?

    If not, does Windows offer some interface to programmatically create file associations?

    I think there's a solution cause a know of many programs that write and create file association.

    Thank you for your help.
    Thursday, February 7, 2008 5:52 PM

All replies

  • Hi - I think my information can help:

    Well, first off, you can make a Setup.exe file, which will add those
    registry values. And the Setup.exe will automatically, run as administrator
    in Windows Vista.

    However, if you want to modify the permission of a regpath, then
    you need to use the "RegistryPermission " class, and call the enumerator (orginal "enum"),
    which is the "RegistryPermissionAccess" and use like this:

    ------------------------------------------------------------------------------
    Try
    {

    RegistryPermission permission = new RegistryPermission( RegistryPermissionAccess.AllAccess, "HKEY_CLASSES_ROOT\");
    //Here we perform the "Demand()" function, which
    //will change the Permission to "AllAccess".
    permission.Demand();

    }
    catch(Exception ex){
         MessageBox.Show(ex.Message.ToString());
    }
    --------------------------------------------------------------------------------
    Security Note: The above code might require administrator privileges.
     

    For further reading:
    RegistryPermission Class:
    http://msdn.microsoft.com/en-us/library/system.security.permissions.registrypermission.aspx

    RegistryPermissionAccess Enumeration:
    http://msdn.microsoft.com/en-us/library/system.security.permissions.registrypermissionaccess.aspx



    I hope this information was helpful...

    Best regards,
    Fisnik
    Coder24.com
    • Proposed as answer by Fisnik Hasani Wednesday, October 14, 2009 5:28 PM
    Sunday, October 11, 2009 6:43 PM
  • Hi Stojilcoviz:

    How is the situation on your side?
    Is this thread solved?

    Please tell me!

    Have a nice day...

    Best regards,
    Fisnik
    Coder24.com
    Wednesday, October 14, 2009 5:28 PM
  • Hi again:

    How is the situation on your side?
    Is this thread solved?

    Please tell me!

    Have a nice day...

    Best regards,
    Fisnik
    Coder24.com
    Friday, November 13, 2009 8:16 PM
  • Hi again:

    How is the situation on your side?
    Is this thread solved?

    Please tell me!

    Have a nice day...

    Best regards,
    Fisnik
    Coder24.com
    Thursday, November 26, 2009 12:33 PM
  • Hi again:

    How is the situation on your side?
    Is this thread solved?

    Please tell me!

    Have a nice day...

    Best regards,
    Fisnik
    Coder24.com
    Thursday, December 10, 2009 1:56 PM
  • Hi again:

    How is the situation on your side?
    Is this thread solved?

    Please tell me!

    Have a nice day...

    Best regards,
    Fisnik
    Coder24.com
    Sunday, December 27, 2009 9:34 AM
  • Hi again:

    How is the situation on your side?
    Is this thread solved?

    Please tell me!

    Have a nice day...

    Best regards,
    Fisnik

    Coder24.com
    Saturday, January 2, 2010 3:07 PM