无法在Windows 10上更改注册表

问题描述 投票:0回答:2

我正在尝试使用以下代码在Windows 10上更改Shell注册表项的值:

Public Function overwriteStartup()
    Try
        Dim winlogon As RegistryKey = My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", True)
        winlogon.SetValue("AutoRestartShell", 0, RegistryValueKind.DWord)
        winlogon.SetValue("Shell", Application.ExecutablePath, RegistryValueKind.String)
        winlogon.Flush()
        winlogon.Close()
        Return True
    Catch ex As Exception
        Return False
    End Try
End Function

问题是Shell和AutoRestartShell没有更改。如果在MessageBox.Show(My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon").GetValue("Shell"))winlogon.Close()之间添加Return True,则会得到一个显示正确值的消息框(这意味着该值已更改),但是当我检查regedit时,它会显示原始值,因此实际不更改值。Diffinent values, should be the same

windows vb.net registry
2个回答
0
投票
读取注册表值-您必须先提供管理特权,然后才能让您的应用程序编写注册表值。转到应用清单,并将特权设置为requireAdministrator,然后重试,应该可以。

如果删除异常处理Try Catch,则将了解确切原因。


0
投票
© www.soinside.com 2019 - 2024. All rights reserved.