以下代码删除了注册表项,但从未进入 for 循环(它应该进入,因为它会检查该值是否已被删除)为什么会这样?(我使用的是 Windows 10 - 64 位)当我导航到那里时,LocalMachine\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run我看不到任何HackerOne扫描仪值!(我创建后就检查过) RegistryKey rk1 = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); rk1.DeleteValue("HackerOne Scanner", false); if (Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", "true", true) == null) { try { RegistryKey rk = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); rk.SetValue("HackerOne Scanner", Application.ExecutablePath); } catch { MessageBox.Show("Admin Rights Are Required"); Application.Exit(); } }
1 回答
GCT1015
TA贡献1827条经验 获得超4个赞
Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", "true", true)true未找到值时返回,而不是 ,因为您作为默认值null传递。但是您可以作为默认值true传递。null
Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", "true", null);但是请注意,您正在搜索的值不是您随后设置的值truevs "HackerOne Scanner"。那可能不是故意的。
- 1 回答
- 0 关注
- 159 浏览
添加回答
举报
0/150
提交
取消
