Reputation: 1735
This is something that I have to once and will never have to do it again. I want to create REG_BINARY from a string. There's a program that encodes the password and stores it in the registry as REG_BINARY. I have copied the REG_BINARY and stored it in my database as varchar (i.e. string). So, whenever user logs in to any computer in the network, this REG_BINARY needs to be applied to the Registry value.
Here's what I tried.
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"
The USER_ID
shows up in the registry, but not the DEPARTMENT_PASS
. I think it's cause the department_pass is stored as string. The value of the department_pass from the database is:
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
The registry needs to show this value exactly the way it is. How can I do this?
Upvotes: 1
Views: 2530
Reputation: 1735
Since I don't have to write VB scripts a lot, I didn't really care to learn it much. I do understand what @Ansgar Wiechers was trying to do, but it didn't work out for me. However, I found this link https://rcmtech.wordpress.com/2012/03/06/vbscript-and-reg_binary-registry-values/ that pointed me to the write direction. I just had to adjust a couple things for my need and get the value from the database, then it worked.
Upvotes: 0
Reputation: 200273
When in doubt, read the documentation:
RegWrite will write at most one DWORD to a REG_BINARY value. Larger values are not supported with this method.
What you're trying to do requires the SetBinaryValue
WMI method:
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
Since SetBinaryValue
expects value
to be an array of integers you need to convert the value of objRecordset("DEPARTMENT_PASS")
(probably a string) to that first:
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
Upvotes: 3