Algoritmo que recorra todo el registro

26/02/2007 - 04:06 por Pietro | Informe spam
Hola a todos, tuve un problema al intentar obtener todas las llaves del
registro de local machine:
Para ir probando el algoritmo hice un formulario con 2 listbox:

RegistryKey reg = Registry.LocalMachine;
string[] llaves = reg.GetSubKeyNames();
for (int i = 0; i < llaves.Length; i++)
{
listBox1.Items.Add(llavesIdea.ToString());
}


Hasta ahi todo bien, lo que me arroja error es cuando intento abrir las
subkeys

foreach (string subKeys in reg.OpenSubKey(holaIdea))

Pero no me deja: Error 1 foreach statement cannot operate on variables
of type 'Microsoft.Win32.RegistryKey' because 'Microsoft.Win32.RegistryKey'
does not contain a public definition for 'GetEnumerator' C:\Documents and
Settings\Pietro\Mis documentos\Visual Studio
2005\Projects\WindowsApplication2\WindowsApplication2\Form1.cs 37 17
WindowsApplication2

Que se les ocurre??
 

Leer las respuestas

#1 Alberto Poblacion
26/02/2007 - 08:02 | Informe spam
"Pietro" wrote in message
news:
foreach (string subKeys in reg.OpenSubKey(holaIdea))

Pero no me deja: Error 1 foreach statement cannot operate on
variables
of type 'Microsoft.Win32.RegistryKey' because
'Microsoft.Win32.RegistryKey'
does not contain a public definition for 'GetEnumerator'



El "OpenSubKey" te devuelve un objeto de tipo RegistryKey, que no es
Enumerable y por tanto no se puede recorrer con un foreach. Para obtener las
subclaves tienes que llamar a su método GetSubKeyNames, que te devuelve un
array de Strings (que sí es enumerable).

Preguntas similares