可能重复:
检查注册表权限而不抛出异常
检查 RegistryKey 编辑的权限如何更正确?现在我写这样的代码:
RegistryKey regKey = null;
try {
regKey = Registry.LocalMachine.OpenSubKey("Software", true);
}
catch (SecurityException ex) {
Console.WriteLine("SecurityException: {0}", ex.Message);
}
catch (Exception ex) {
Console.WriteLine("Exception: {0}", ex.Message);
}
if (null == regKey)
Console.WriteLine("Registry key not exists, or you have not necessary permission for edit it.");
else
Console.WriteLine("Registry key successfully opened. You have necessary permission for edit it.");
但是异常对性能影响非常大。我可以在没有 try/catch 的情况下检查它吗?
最好的问候,安德烈