C# Работа с реестром framework 2.0
Нахожу катало java при помощи следующего кода:
/** * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann * (http://qbnz.com/highlighter/ and http://geshi.org/) */ .csharp.geshi_code {font-family:monospace;} .csharp.geshi_code .imp {font-weight: bold; color: red;} .csharp.geshi_code .kw1 {color: #0600FF;} .csharp.geshi_code .kw2 {color: #FF8000; font-weight: bold;} .csharp.geshi_code .kw3 {color: #008000;} .csharp.geshi_code .kw4 {color: #FF0000;} .csharp.geshi_code .kw5 {color: #000000;} .csharp.geshi_code .co1 {color: #008080; font-style: italic;} .csharp.geshi_code .co2 {color: #008080;} .csharp.geshi_code .co3 {color: #008080;} .csharp.geshi_code .coMULTI {color: #008080; font-style: italic;} .csharp.geshi_code .es0 {color: #008080; font-weight: bold;} .csharp.geshi_code .es_h {color: #008080; font-weight: bold;} .csharp.geshi_code .br0 {color: #000000;} .csharp.geshi_code .sy0 {color: #008000;} .csharp.geshi_code .st0 {color: #666666;} .csharp.geshi_code .st_h {color: #666666;} .csharp.geshi_code .nu0 {color: #FF0000;} .csharp.geshi_code .me1 {color: #0000FF;} .csharp.geshi_code .me2 {color: #0000FF;} .csharp.geshi_code span.xtra { display:block; }
RegistryKey register = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
foreach (string section in register.OpenSubKey(@"SOFTWARE").GetSubKeyNames())
{
if (section == "JavaSoft")
{
foreach (string subsection in register.OpenSubKey(@"SOFTWAREJavaSoft").GetSubKeyNames())
{
switch (subsection)
{
case "Java Runtime Environment":
foreach (string version in register.OpenSubKey(@"SOFTWAREJavaSoftJava Runtime Environment").GetSubKeyNames())
{
if (File.Exists((string)register.OpenSubKey(@"SOFTWAREJavaSoftJava Runtime Environment" + version).GetValue("JavaHome") + @"binjavaw.exe"))
{
register.Close();
return (string)register.OpenSubKey(@"SOFTWAREJavaSoftJava Runtime Environment" + version).GetValue("JavaHome") + @"binjavaw.exe";
}
}
break;
case "Java Development Kit":
foreach (string version in register.OpenSubKey(@"SOFTWAREJavaSoftJava Development Kit").GetSubKeyNames())
{
if (File.Exists((string)register.OpenSubKey(@"SOFTWAREJavaSoftJava Development Kit" + version).GetValue("JavaHome") + @"binjavaw.exe"))
{
register.Close();
return (string)register.OpenSubKey(@"SOFTWAREJavaSoftJava Development Kit" + version).GetValue("JavaHome") + @"binjavaw.exe";
}
}
break;
}
}
}
}
register.Close();
Вопрос как оптимизировать этот код по framework 2.0? /** * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann * (http://qbnz.com/highlighter/ and http://geshi.org/) */ .csharp.geshi_code {font-family:monospace;} .csharp.geshi_code .imp {font-weight: bold; color: red;} .csharp.geshi_code .kw1 {color: #0600FF;} .csharp.geshi_code .kw2 {color: #FF8000; font-weight: bold;} .csharp.geshi_code .kw3 {color: #008000;} .csharp.geshi_code .kw4 {color: #FF0000;} .csharp.geshi_code .kw5 {color: #000000;} .csharp.geshi_code .co1 {color: #008080; font-style: italic;} .csharp.geshi_code .co2 {color: #008080;} .csharp.geshi_code .co3 {color: #008080;} .csharp.geshi_code .coMULTI {color: #008080; font-style: italic;} .csharp.geshi_code .es0 {color: #008080; font-weight: bold;} .csharp.geshi_code .es_h {color: #008080; font-weight: bold;} .csharp.geshi_code .br0 {color: #000000;} .csharp.geshi_code .sy0 {color: #008000;} .csharp.geshi_code .st0 {color: #666666;} .csharp.geshi_code .st_h {color: #666666;} .csharp.geshi_code .nu0 {color: #FF0000;} .csharp.geshi_code .me1 {color: #0000FF;} .csharp.geshi_code .me2 {color: #0000FF;} .csharp.geshi_code span.xtra { display:block; }
RegistryKey register = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
В частности интересует как попасть в реестр 32x из под 64х разрядной системы.
/** * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann * (http://qbnz.com/highlighter/ and http://geshi.org/) */ .csharp.geshi_code {font-family:monospace;} .csharp.geshi_code .imp {font-weight: bold; color: red;} .csharp.geshi_code .kw1 {color: #0600FF;} .csharp.geshi_code .kw2 {color: #FF8000; font-weight: bold;} .csharp.geshi_code .kw3 {color: #008000;} .csharp.geshi_code .kw4 {color: #FF0000;} .csharp.geshi_code .kw5 {color: #000000;} .csharp.geshi_code .co1 {color: #008080; font-style: italic;} .csharp.geshi_code .co2 {color: #008080;} .csharp.geshi_code .co3 {color: #008080;} .csharp.geshi_code .coMULTI {color: #008080; font-style: italic;} .csharp.geshi_code .es0 {color: #008080; font-weight: bold;} .csharp.geshi_code .es_h {color: #008080; font-weight: bold;} .csharp.geshi_code .br0 {color: #000000;} .csharp.geshi_code .sy0 {color: #008000;} .csharp.geshi_code .st0 {color: #666666;} .csharp.geshi_code .st_h {color: #666666;} .csharp.geshi_code .nu0 {color: #FF0000;} .csharp.geshi_code .me1 {color: #0000FF;} .csharp.geshi_code .me2 {color: #0000FF;} .csharp.geshi_code span.xtra { display:block; }
RegistryKey register = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
foreach (string section in register.OpenSubKey(@"SOFTWARE").GetSubKeyNames())
{
if (section == "JavaSoft")
{
foreach (string subsection in register.OpenSubKey(@"SOFTWAREJavaSoft").GetSubKeyNames())
{
switch (subsection)
{
case "Java Runtime Environment":
foreach (string version in register.OpenSubKey(@"SOFTWAREJavaSoftJava Runtime Environment").GetSubKeyNames())
{
if (File.Exists((string)register.OpenSubKey(@"SOFTWAREJavaSoftJava Runtime Environment" + version).GetValue("JavaHome") + @"binjavaw.exe"))
{
register.Close();
return (string)register.OpenSubKey(@"SOFTWAREJavaSoftJava Runtime Environment" + version).GetValue("JavaHome") + @"binjavaw.exe";
}
}
break;
case "Java Development Kit":
foreach (string version in register.OpenSubKey(@"SOFTWAREJavaSoftJava Development Kit").GetSubKeyNames())
{
if (File.Exists((string)register.OpenSubKey(@"SOFTWAREJavaSoftJava Development Kit" + version).GetValue("JavaHome") + @"binjavaw.exe"))
{
register.Close();
return (string)register.OpenSubKey(@"SOFTWAREJavaSoftJava Development Kit" + version).GetValue("JavaHome") + @"binjavaw.exe";
}
}
break;
}
}
}
}
register.Close();
Вопрос как оптимизировать этот код по framework 2.0? /** * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann * (http://qbnz.com/highlighter/ and http://geshi.org/) */ .csharp.geshi_code {font-family:monospace;} .csharp.geshi_code .imp {font-weight: bold; color: red;} .csharp.geshi_code .kw1 {color: #0600FF;} .csharp.geshi_code .kw2 {color: #FF8000; font-weight: bold;} .csharp.geshi_code .kw3 {color: #008000;} .csharp.geshi_code .kw4 {color: #FF0000;} .csharp.geshi_code .kw5 {color: #000000;} .csharp.geshi_code .co1 {color: #008080; font-style: italic;} .csharp.geshi_code .co2 {color: #008080;} .csharp.geshi_code .co3 {color: #008080;} .csharp.geshi_code .coMULTI {color: #008080; font-style: italic;} .csharp.geshi_code .es0 {color: #008080; font-weight: bold;} .csharp.geshi_code .es_h {color: #008080; font-weight: bold;} .csharp.geshi_code .br0 {color: #000000;} .csharp.geshi_code .sy0 {color: #008000;} .csharp.geshi_code .st0 {color: #666666;} .csharp.geshi_code .st_h {color: #666666;} .csharp.geshi_code .nu0 {color: #FF0000;} .csharp.geshi_code .me1 {color: #0000FF;} .csharp.geshi_code .me2 {color: #0000FF;} .csharp.geshi_code span.xtra { display:block; }
RegistryKey register = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);