Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Registry access GetSubKeyNames() troubleshooting

Status
Not open for further replies.

destroyhead

Programmer
Feb 22, 2006
27
0
0
GB
Hi,

Here is my code :

using System;

using System.Security;

using System.Security.Permissions;

using System.Collections;

using Microsoft.Win32;

class Reg

{

RegistryPermission readPerm1 = new RegistryPermission(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE");

public static void Main()

{

// Create a RegistryKey, which will access the HKEY_LOCAL_MACHINE

// key in the registry of this machine.

RegistryKey rk = Registry.LocalMachine;

// Print out the keys.

PrintKeys(rk);

}

static void PrintKeys(RegistryKey rkey)

{

// Retrieve all the subkeys for the specified key.

String[] names = rkey.GetSubKeyNames();

int icount = 0;

Console.WriteLine("Subkeys of " + rkey.Name);

Console.WriteLine("-----------------------------------------------");

// Print the contents of the array to the console.

foreach (String s in names)

{

Console.WriteLine(s);

// The following code puts a limit on the number

// of keys displayed. Comment it out to print the

// complete list.

icount++;

if (icount >= 10)

break;

}

}

}

When running I have the error :

"Request for the permission of type 'System.Security.Permissions.RegistryPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed." related to the GetSubKeyNames() function.

I am administrator on my box and can create Registry keys. I have also given the full access to the VS Developers groups on the registry.

Thanks for your help.

Olivier
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top