欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

c#下注冊(cè)表操作的一個(gè)小細(xì)節(jié)

 更新時(shí)間:2007年11月06日 19:21:05   作者:  
先看一個(gè)有錯(cuò)誤的代碼:

string subKeyName = @"Software\Microsoft\Windows\CurrentVersion\Run\"; //subkey name
string valueName = @"App Name"; //name of the more specific key that will hold the value, "" means (Default)
try
...{
RegistryKey reg = Registry.LocalMachine.OpenSubKey(subKeyName);
if (reg != null)
...{
reg.DeleteValue(valueName);
reg.Close();
}
}
catch (Exception ex)
...{
MessageBox.Show(this, ex.ToString());
}
執(zhí)行這段代碼,你可以會(huì)收到以下異常:
System.UnauthorizedAccessException
原因很簡(jiǎn)單:
RegistryKey.OpenSubKey (String) 以只讀方式檢索子項(xiàng)
public RegistryKey OpenSubKey ( string name, bool writable)writable如果需要項(xiàng)的寫(xiě)訪問(wèn)權(quán)限,則設(shè)置為 true。 
我們需要帶第二個(gè)參數(shù),標(biāo)示我們是可寫(xiě)方式打開(kāi)的。

相關(guān)文章

最新評(píng)論