Vbscript 从注册表读取DefaultUserName键值时出现Visual basic问题
几周前,我编写了一个vbscript来获取远程计算机的DefaultUserName键值。那张纸条很好用。我正试图从VB.net应用程序中执行同样的操作,但结果一无所获。我也从我的vb应用程序中启动了相同的脚本,我得到了相同的结果。看起来该脚本单独运行良好,但如果用户从vb.net应用程序启动它,则无法正常运行。下面是我用来获取注册表值的vb代码,该代码也没有得到任何结果。我需要在vb环境中设置一些东西吗?会发生什么?任何帮助都将不胜感激。谢谢Vbscript 从注册表读取DefaultUserName键值时出现Visual basic问题,vbscript,Vbscript,几周前,我编写了一个vbscript来获取远程计算机的DefaultUserName键值。那张纸条很好用。我正试图从VB.net应用程序中执行同样的操作,但结果一无所获。我也从我的vb应用程序中启动了相同的脚本,我得到了相同的结果。看起来该脚本单独运行良好,但如果用户从vb.net应用程序启动它,则无法正常运行。下面是我用来获取注册表值的vb代码,该代码也没有得到任何结果。我需要在vb环境中设置一些东西吗?会发生什么?任何帮助都将不胜感激。谢谢 Private Sub askComputer2(
Private Sub askComputer2(ByVal computer, ByRef text)
Dim strKeyPath As String, strEntryName As String, comment As String, strValue As String
'Dim objReg As Object
Const HKEY_LOCAL_MACHINE = &H80000002
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
strEntryName = "ReportBootOk"
comment = ""
strValue = ""
'text = "Computer Name = " & computer & vbNewLine & vbNewLine
On Error Resume Next
Dim objReg As Object = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & computer & "\root\cimv2")
If Err.Number <> 0 Then
text = "It was not possible to get Autologin information for " & computer & vbNewLine & "Error: " & Err.Number & " Source: " & Err.Source & " Description: " & Err.Description
Err.Clear()
Else
'MsgBox(objReg.Value(HKEY_LOCAL_MACHINE, strKeyPath, strEntryName, strValue).ToString())
strValue = objReg.Value(HKEY_LOCAL_MACHINE, strKeyPath, strEntryName, strValue).ToString()
MsgBox(strValue)
If strValue = "1" Then
comment = " (Autologin machine)"
ElseIf strValue = "0" Then
comment = " (Non Autologin machine)"
End If
text = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoAdminLogon = " & strValue & comment
strEntryName = "DefaultUserName"
objReg.GetStringValue(HKEY_LOCAL_MACHINE, strKeyPath, strEntryName, strValue)
text = text & " HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName = " & strValue
MsgBox(text, , "Autologin Check")
End If
End Sub
专用子ASK计算机2(ByVal计算机,ByRef文本)
Dim strKeyPath作为字符串,strEntryName作为字符串,comment作为字符串,strValue作为字符串
“Dim objReg作为对象”
Const HKEY_本地_机器=&H8000002
strKeyPath=“软件\Microsoft\Windows NT\CurrentVersion\Winlogon”
strEntryName=“ReportBootOk”
comment=“”
strValue=“”
'text=“Computer Name=”&Computer&vbNewLine&vbNewLine
出错时继续下一步
Dim objReg As Object=GetObject(“winmgmts:_
&“{impersonationLevel=impersonate}!\\”&computer&“\root\cimv2”)
如果错误号为0,则
text=“无法获取“&computer&vbNewLine&”错误:&Err.Number&”源:&Err.Source&“Description:&Err.Description:”的自动登录信息
错误清除()
其他的
'MsgBox(objReg.Value(HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strrvalue).ToString())
strValue=objReg.Value(HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue).ToString()
MsgBox(标准值)
如果strValue=“1”,则
comment=“(自动登录机)”
ElseIf strValue=“0”则
comment=“(非自动登录机器)”
如果结束
text=“HKEY\U LOCAL\U MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoAdminLogon=“&strValue&comment
strEntryName=“DefaultUserName”
objReg.GetStringValue(HKEY_LOCAL_机器、strKeyPath、strEntryName、strValue)
text=text&“HKEY\U LOCAL\U MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName=“&strValue
MsgBox(文本,“自动登录检查”)
如果结束
端接头
您可能会遇到。对于32位进程,从HKLM\SOFTWARE\Wow6432Node
读取HKLM\SOFTWARE
下的键,导致结果混乱。如果使用RegEdit修改HKEY\U LOCAL\U MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName
,您应该会看到它是代码正在读取的值
您可以使用带有相应视图选项(.NET 4.0+)的方法,从32位(或64位)进程读取64位注册表项:
多亏了马克,我才能得到这个密码。它将能够获取网络上任何计算机的AutoAdminLogon和DefaultUserName注册表值
Private Sub askComputer1(ByVal computer)
MsgBox(computer)
Dim environmentKey As RegistryKey
Dim val1 As String, val2 As String
environmentKey = RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, computer, RegistryView.Registry64).OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon")
val1 = environmentKey.GetValue("AutoAdminLogon").ToString()
val2 = environmentKey.GetValue("DefaultUserName").ToString()
MsgBox(val1 & " " & val2)
environmentKey.Close()
End Sub
VB.net和vbscript是两种完全不同的语言。@JoelCoehoorn问题是“我正试图从VB.net应用程序中执行相同的操作,但结果一无所获”,所以我假设这与VB.net有关。。。但我可能错了。谢谢Marl,我有点沮丧:(,我也尝试了下面的代码,但也失败了…MsgBox(计算机)Dim environmentKey作为RegistryKey Dim text1作为String environmentKey=RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine,computer)。OpenSubKey(“SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon”,False)text=CStr(environmentKey.GetValue(“DefaultUserName”),“?”)MsgBox(text)@jcnuez如果要打开远程注册表,则需要使用重载-RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine,computer,RegistryView.Registry64)
。
Private Sub askComputer1(ByVal computer)
MsgBox(computer)
Dim environmentKey As RegistryKey
Dim val1 As String, val2 As String
environmentKey = RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, computer, RegistryView.Registry64).OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon")
val1 = environmentKey.GetValue("AutoAdminLogon").ToString()
val2 = environmentKey.GetValue("DefaultUserName").ToString()
MsgBox(val1 & " " & val2)
environmentKey.Close()
End Sub