Tech Off Thread

4 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Registry permissions troubles

Back to Forum: Tech Off
  • User profile image
    vbrunner__

    IdentityReference refer = new NTAccount(Environment.UserDomainName,
        Environment.UserName);
    RegistryAccessRule full = new RegistryAccessRule(refer,
        RegistryRights.FullControl, AccessControlType.Allow);
    RegistrySecurity sec = new RegistrySecurity();
    sec.AddAccessRule(full);

    RegistryKey key = Registry.LocalMachine.OpenSubKey(
        @"SOFTWARE\Microsoft\VSTAHostConfig");
    key = key.CreateSubKey("TestApp",
        RegistryKeyPermissionCheck.ReadWriteSubTree, sec);
    // Validate args first.
    key.SetValue("AppName", args[0],
        RegistryValueKind.String);
    key.SetValue("ProjectTemplateLocations", args[1],
        RegistryValueKind.String);
    // done!


    the above code should add the keys necessary to register a VSTA application to prepare it to create project templates.  problem is, .NET is telling me it can't change the registry.
    Are my security checks incorrect?  i'm on a corporate network, but i'm local admin on all machines in my domain, including of course my own.

    any help?

  • User profile image
    jasgrg

    Try

    RegistryKey key = Registry.LocalMachine.OpenSubKey(
        @"SOFTWARE\Microsoft\VSTAHostConfig", true);


    It opens the subkey as writeable.

  • User profile image
    evildictait​or

    Also be careful on Vista - some registry keys need administrator permissions to write to.

  • User profile image
    vbrunner__

    jasgrg wrote:
    Try

    RegistryKey key = Registry.LocalMachine.OpenSubKey(
        @"SOFTWARE\Microsoft\VSTAHostConfig", true);


    It opens the subkey as writeable.


    wow.  figures it would be something that simple.
    thanks.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.