這是我的 C# 代碼:
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Multimedia\SystemProfile", true))
{
key.CreateSubKey("NetworkThrottlingIndex");
key.SetValue("NetworkThrottlingIndex", "0000000a", RegistryValueKind.DWord);
key.CreateSubKey("SystemResponsiveness");
key.SetValue("SystemResponsiveness", "00000000", RegistryValueKind.DWord);
key.CreateSubKey("NoLazyMode");
key.SetValue("NoLazyMode", "1");
}
所以這里發生的是我收到一個錯誤
System.NullReferenceException
在線上
key.CreateSubKey("NetworkThrottlingIndex");
因為密鑰為空。
我檢查了幾次,但這個鍵存在于我的注冊表編輯器中。
關于這里有什么問題的任何想法?
uj5u.com熱心網友回復:
SOFTWARE 注冊表項的重定向取決于您的應用程式和 Windows 的位數。
要通過 x86/32 位 EXE(在 64 位 Windows 上)訪問您的密鑰,請請求 64 位注冊表視圖:
using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
using (var key = hklm.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Multimedia\SystemProfile", RegistryKeyPermissionCheck.ReadWriteSubTree))
{
...
}
另請注意,這NetworkThrottlingIndex是一個子鍵(即“檔案夾”),因此您無法設定它的值,因為它沒有。此外,您可以將十六進制文字用于 DWORD 值 ( 0x0000000a) 而不是字串。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/521565.html
標籤:C#视窗登记处注册表项
上一篇:在NSScrollView(AppKit)上檢測滑鼠滾輪-END-事件
下一篇:寫入comport時出現分段錯誤
