这是我必须要做的事情,而且永远不会再这样做了。我想从字符串创建REG_BINARY。有一个程序对密码进行编码并将其作为REG_BINARY存储在注册表中。我复制了REG_BINARY并将其作为varchar(即字符串)存储在我的数据库中。因此,每当用户登录到网络中的任何计算机时,都需要将此REG_BINARY应用于Registry值。
这是我尝试过的。
Set oShell = CreateObject("WScript.Shell")
Set oFso = CreateObject("Scripting.FileSystemObject")
'Create the ADsystem Information Object
Set objADSystemInfo = CreateObject("ADSystemInfo")
'Get the current information into a new object
Set objUser = GetObject("LDAP://" & objADSystemInfo.UserName)
'Office Details
oShell.RegWrite "HKCU\Software\Microsoft\Office\Common\UserInfo\UserInitials", objUser.sAMAccountName, "REG_SZ"
oShell.RegWrite "HKCU\Software\Microsoft\Office\Common\UserInfo\UserName", objUser.givenName & " " & objUser.sn, "REG_SZ"
On Error Resume Next
'Connect to MySQL Database
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open "DSN=members;"
objRecordset.CursorLocation = adUseClient
objRecordset.ActiveConnection = objConnection
objRecordset.Open "SELECT * FROM members WHERE USER_ID = '" & objUser.sAMAccountName & "'"
aRegPath = "HKCU\Software\KONICA MINOLTA\KONICA MINOLTA 350/250/200 VXL\AccountTrack\"
oShell.RegWrite aRegPath & "DepartmentName", objRecordset("USER_ID"), "REG_SZ"
oShell.RegWrite aRegPath & "DepartmentPass", objRecordset("DEPARTMENT_PASS"), "REG_BINARY"
USER_ID
显示在注册表中,但不显示在DEPARTMENT_PASS
中。我认为这是因为department_pass存储为字符串。来自数据库的department_pass的值为:
be 2e 31 df ff 53 ca 35 f8 32 90 22 fc 44 4b 66 f8 32 90 22 fc 44 4b 66 f8 32 90 22 fc 44 4b 66 f8 32 90 22 fc 44 4b 66 f8 32 90 22 fc 44 4b 66 f8 32 90 22 fc 44 4b 66 f8 32 90 22 fc 44 4b 66 32 88 64 99 7b ab 8d 3c
注册表需要完全按照它的方式显示此值。我怎样才能做到这一点?
答案 0 :(得分:2)
如有疑问,请阅读documentation:
RegWrite 最多会将一个DWORD写入REG_BINARY值。此方法不支持更大的值。
您要做的事情需要SetBinaryValue
WMI方法:
Const HKCU = &h80000001
Set reg = GetObject("winmgmts://./root/default:StdRegProv")
key = "Software\KONICA MINOLTA\KONICA MINOLTA 350/250/200 VXL\AccountTrack"
name = "DepartmentPass"
value = Array(1, 2, 3, 4, 5, 6, 7, 8, 9)
rc = reg.SetBinaryValue(HKCU, key, name, value)
If rc <> 0 Then
WScript.Echo "Error setting binary value"
WScript.Quit 1
End If
由于SetBinaryValue
期望value
是一个整数数组,您需要将objRecordset("DEPARTMENT_PASS")
(可能是一个字符串)的值转换为第一个:
str = objRecordset("DEPARTMENT_PASS")
ReDim value(Len(str) - 1)
For i = 1 To Len(str)
c = Mid(str, i, 1)
value(i-1) = Asc(c)
Next
答案 1 :(得分:0)
由于我不需要编写很多VB脚本,所以我并不在乎学习它。我确实理解@Ansgar Wiechers试图做的事情,但这对我没有用。但是,我发现此链接 https://rcmtech.wordpress.com/2012/03/06/vbscript-and-reg_binary-registry-values/指向了写入方向。我只需根据需要调整一些东西并从数据库中获取值,然后就可以了。