Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 尝试在注册表中添加我的用户名以获得读取权限,我尝试使用源代码,但没有将我的用户添加到注册表->;许可_Vb.net_Windows 10_Registrykey - Fatal编程技术网

Vb.net 尝试在注册表中添加我的用户名以获得读取权限,我尝试使用源代码,但没有将我的用户添加到注册表->;许可

Vb.net 尝试在注册表中添加我的用户名以获得读取权限,我尝试使用源代码,但没有将我的用户添加到注册表->;许可,vb.net,windows-10,registrykey,Vb.net,Windows 10,Registrykey,尝试实际地向用户添加读取权限时,我没有收到错误,但没有添加到注册表中 Dim Keyss = Microsoft.Win32.Registry.Users try For Each a In Keyss.GetSubKeyNames Dim key = Keyss.OpenSubKey(a) Next ' key = Keyss.OpenSubKey("S-1-5-20") Catch ex As SecurityE

尝试实际地向用户添加读取权限时,我没有收到错误,但没有添加到注册表中

    Dim Keyss = Microsoft.Win32.Registry.Users
    try
    For Each a In Keyss.GetSubKeyNames
            Dim key = Keyss.OpenSubKey(a)
    Next 
    '    key = Keyss.OpenSubKey("S-1-5-20")
    Catch ex As SecurityException
        'Dim rs = Keyss.GetAccessControl()
        Dim rs As New RegistrySecurity()
        'Dim currentUserStr = Environment.UserDomainName + "\" + Environment.UserName
        Dim currentUserStr = Environment.UserName
        Try
            rs.AddAccessRule(New RegistryAccessRule(currentUserStr, RegistryRights.ReadKey, AccessControlType.Allow))
        Catch exw As Exception
              MsgBox(exw.ToString)
        End Try
    End Try

尝试逐行调试代码。同时显示错误消息。您的内部
Catch
为空,因此无法获取错误。感谢您的回复。我已经补充说,仍然没有在异常黑色中得到任何错误。不适用于您的问题,但我相信密钥实现了
IDisposable
,因此应该手动处理或使用
块封装在
中。