Registret
Har följande funktion
<code>
internal static string hämtaInst(string strNamn, string strStandard)
{
RegistryKey keyNyckel=Registry.CurrentUser.OpenSubKey("Software\\TeliaADSL3");
if(keyNyckel==null)
{
keyNyckel=Registry.CurrentUser.CreateSubKey("Software\\TeliaADSL3");
}
return keyNyckel.GetValue(strNamn,strStandard).ToString();
}
</code>
(hade förut <code>
internal static string hämtaInst(string strNamn, string strStandard)
{
return Registry.CurrentUser.CreateSubKey("Software\\TeliaADSL3").GetValue(strNamn,strStandard).ToString();
}
</code>)
Men jag får inte ut nåt.....
Kan det vara nåt med att den inte kör statiskt (den _är_ static men anropas från en "dotterklass")
Mr T @thomassida.cjb.net
PS. Det här stod i MSDN:
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows .NET Server family
.NET Framework Security:
RegistryPermission for the ability to read the specified registry key. Associated enumeration: Read
SecurityPermission for the ability to access unmanaged code if the specified registry key is a remote key. Associated enumeration: UnmanagedCode
Svara
Sv: Registret
Prova med att lägga till true när du försöker att öppna keyNyckel
....("Software//TeliaADSL3",true)
Peter
Svara
Sv: Registret
Hehe, kanske rätt på opensubkey, men du gav mig svaret utan att kanske veta det: // istf \Nu funkar min första funktion :D (inom parentes på mitt tidigare inlägg)
Edit.
Varför // vid läsning och \\ vid sparning?
Mr T @thomassida.cjb.net
Svara
Sv: Registret
Även om det verkar som om du löst problemet så klistrar jag här in två generiska metoder som jag använder för att läsa och skriva till registret:
<code>
/// <summary>
/// Set or update a value post under the current key.
/// </summary>
/// <param name="Name">Name of the value post</param>
/// <param name="Value">Value of the post.</param>
public void SetKeyValue(string Name, object Value)
{
try
{
// Create a ref to the base key
RegistryKey BaseKey = Registry.LocalMachine.OpenSubKey("SOFTWARE",true);
if(KeyPath != null)
{
// Opens the subkey based on KeyPath.
RegistryKey SubKey = BaseKey.CreateSubKey(KeyPath);
// Create or update the value post.
SubKey.SetValue(Name,Value);
}
}
catch(Exception e)
{
throw e;
}
}
/// <summary>
/// Get value from a value post under the current subkey.
/// </summary>
/// <param name="Name">Name of the value post.</param>
/// <returns>Value or null if it does not exist.</returns>
public object GetKeyValue(string Name)
{
try
{
// Create a ref to the base key
RegistryKey BaseKey = Registry.LocalMachine.OpenSubKey("SOFTWARE",false);
if(KeyPath != null)
{
// Opens the subkey based on KeyPath.
RegistryKey SubKey = BaseKey.CreateSubKey(KeyPath);
// Get key value
return SubKey.GetValue(Name);
}
else
{
return null;
}
}
catch(Exception e)
{
throw e;
}
}
</code>
MVH Andreas.Net
Svara