Vb.net VB网络读取远程注册表

Vb.net VB网络读取远程注册表,vb.net,Vb.net,我试图了解许多远程PC的体系结构和操作系统。 为了做到这一点,我正在查询Win32_OperatingSystem并解析O.S.和我正在阅读的OSArchitecture的架构的“标题”。 在Windows XP中,此值不存在,因此我认为读取HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR\U体系结构 将完成如下代码所示的技巧: Try Dim

我试图了解许多远程PC的体系结构和操作系统。 为了做到这一点,我正在查询Win32_OperatingSystem并解析O.S.和我正在阅读的OSArchitecture的架构的“标题”。 在Windows XP中,此值不存在,因此我认为读取HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR\U体系结构 将完成如下代码所示的技巧:

            Try

            Dim co As New ConnectionOptions
            co.Impersonation = ImpersonationLevel.Impersonate
            co.Authentication = AuthenticationLevel.PacketPrivacy
            co.EnablePrivileges = True

            co.Username = username
            co.Password = password

            Dim scope As New ManagementScope("\\" & machine.Text & "\root\cimv2", co)

            scope.Connect()

            Dim environmentKey, asd2 As Microsoft.Win32.RegistryKey
            Dim asd As String

            environmentKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, machine.Text)
            asd2 = environmentKey.OpenSubKey("SYSTEM\CurrentControlSet\Control\Session Manager\Environment", True)
            asd = asd2.GetValue("PROCESSOR_ARCHITECTURE")

            Debug.Print("asd: " + asd)

            environmentKey.Close()

        Catch ex As Exception

            MessageBox.Show(ex.ToString)

        End Try
我的问题是:如果我尝试此代码,我会得到System.Security.SecurityException:“不允许访问远程注册表”

我是,我知道管理员的用户名和密码。 事实上,如果我运行一个简单的cmdkey/add:targetname/user:username/pass:password 它起作用了

那么,即使我已经在ConnectionOptions中指定了用户名和密码,为什么还要运行cmdkey/add呢


另外,很抱歉我的英语不好

这很可能是因为目标PC上未启用远程注册表访问

即使您知道管理员凭据,如果未在目标PC上启用该功能,远程访问注册表也将不起作用

要启用它,请参阅下面的Microsoft知识库文章,其中介绍了各种Windows操作系统:

好的,我知道了: Const HKEY_当前用户为String=“8000002”


所有远程pc都已启用服务远程注册表。您是否已启用通过防火墙的远程注册表访问?您是否验证是否通过组策略启用了此类访问?是的,它已启用,因为如果未启用,即使执行cmdkey add也无法工作
    Dim options As New ConnectionOptions
    options.Impersonation = ImpersonationLevel.Impersonate
    options.EnablePrivileges = True
    options.Username = ".\administrator"
    options.Password = "my_password"

    Dim myScope As New ManagementScope("\\" & RemotePCHostname & "\root\default", options)
    Dim mypath As New ManagementPath("StdRegProv")
    Dim mc As New ManagementClass(myScope, mypath, Nothing)

    Dim inParams As ManagementBaseObject = mc.GetMethodParameters("GetDWORDValue")
    inParams("hDefKey") =  UInt32.Parse(HKEY_current_user,System.Globalization.NumberStyles.HexNumber) 'RegistryHive.LocalMachine
    inParams("sSubKeyName") = "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
    inParams("sValueName") = "PROCESSOR_ARCHITECTURE"

    Dim outParams As ManagementBaseObject = mc.InvokeMethod("GetStringValue", inParams, Nothing)

    If (outParams("ReturnValue").ToString() = "0") Then
        MessageBox.Show(outParams("sValue").ToString())
    Else
        MessageBox.Show("Error retrieving value : " + outParams("ReturnValue").ToString())
    End If