如果我使用OpenRemoteBaseKey和OpenSubKey,是否需要关闭注册表 [英] Do I need to close registry if i use OpenRemoteBaseKey and OpenSubKey
本文介绍了如果我使用OpenRemoteBaseKey和OpenSubKey,是否需要关闭注册表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我只是想知道是否需要关闭注册表,如果使用以下任何一个(OpenRemoteBaseKey,OpenSubKey等),请参阅下面的代码?感谢您的帮助。
Hello,
I just wondering if i need to close the registry if use any of the following (OpenRemoteBaseKey,OpenSubKey, etc,etc) see code below ? Thanks for your help.
//*************BEGIN GENERAL TAB***********************************
//BROWSING HISTORY/CHECK FOR NEWER VERSIONS OF STORED PAGES
//Select the RegistryHive you wish to read from
RegistryKey key = RegistryKey.OpenRemoteBaseKey(RegistryHive.CurrentUser, "");
//Select the path within the hive
Console.WriteLine("");
RegistryKey subkey1 = key.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
string[] names1 = subkey1.GetValueNames();
string YesSyncMode5NameExists = "";
string NoSyncMode5NameExists = "";
foreach (string name in names1)
{
if (name.Equals("SyncMode5", StringComparison.CurrentCulture))
{
// Found SyncMode5
YesSyncMode5NameExists = "1";
//NoSyncMode5NameExists = "99";
break;
}
else
{
// No Found SyncMode5
NoSyncMode5NameExists = "1";
//subkey1.SetValue("SyncMode5", "2", RegistryValueKind.DWord);
}
}
if (YesSyncMode5NameExists == "1")
{
Console.WriteLine("YES Found SyncMode5");
int myValue = (int)subkey1.GetValue("SyncMode5");
if (myValue != 2)
{
//Console.WriteLine("Setting the right GE Recommendation");
subkey1.SetValue("SyncMode5", "2", RegistryValueKind.DWord);
}
}
if (NoSyncMode5NameExists == "1")
{
//Console.WriteLine("NO Found SyncMode5, creating it ");
//Console.WriteLine("Setting the right GE Recommendation");
subkey1.SetValue("SyncMode5", "2", RegistryValueKind.DWord);
}
推荐答案
您应该像在此代码示例中一样:
http://msdn.microsoft.com/en-us/library/8zha3xws.aspx [ ^ ]。
如果您不关闭,您修改的注册表数据可能会丢失,您需要将其刷新到流,无论文件或网络:http://msdn.microsoft.com/en-us/library/microsoft.win32.registrykey.close.aspx [ ^ ]。
为什么你认为你可以跳过它?为什么?
-SA
You should, like in this code sample:
http://msdn.microsoft.com/en-us/library/8zha3xws.aspx[^].
If you don''t close, your modified Registry data can be lost, you need to flush it to the stream, no matter file or network: http://msdn.microsoft.com/en-us/library/microsoft.win32.registrykey.close.aspx[^].
Why would you think that you can skip it? And why?
—SA
这篇关于如果我使用OpenRemoteBaseKey和OpenSubKey,是否需要关闭注册表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文