destroyhead
Programmer
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
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