1

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?

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

3 Comments

I had to change the syntax to Set reg = GetObject("WinMgmts:root\default:StdRegProv") to get it to work (@ Windows 7)...
@aschipfl Hmm... weird. I have used GetObject("winmgmts://./root/default:StdRegProv") on Windows 7 and other versions (older and newer) for years, if not decades.
I am sorry, stupid me, both variants work, I just had another error in the code and drew a wrong conclusion...
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.