Hello
I need help writing a java script.
My objective is to capture information under this key location. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers.
I originally wrote a VBScript to capture the information. However, I havent made any progress once it failed to capture multi-string and binary values in the subkeys.
(Printer.vbs below)
Const HKLM = &H80000002
Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_MULTI_SZ = 7
strComputer = "."
Set StdOut = WScript.StdOut
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
KeyPath = "SYSTEM\CurrentControlSet\Control\Print\Printers"
objReg.EnumKey HKLM, KeyPath, arrSubKeys
For Each Subkey in arrSubKeys
StdOut.WriteLine "Key: " & subkey
objReg.EnumValues HKLM, KeyPath & "\" & subkey, arrValuenames, arrValuetypes
For I = 0 to UBound(arrValuenames)
Select Case arrvaluetypes(I)
Case REG_SZ
data_type = "String"
Case REG_EXPAND_SZ
data_type = "Expanded String"
Case REG_BINARY
data_type = "Binary"
Case REG_DWORD
data_type = "DWORD"
Case REG_MULTI_SZ
data_type = "Multi String"
End Select
StdOut.Writeline " Value: " & arrvaluenames(I) & " Type= " & data_type
Next
objReg.Enumkey HKLM, KeyPath & "\" & subkey, arrSubSubKeys
For Each SubSubkey in arrSubSubkeys
StdOut.WriteLine " Subkey: " & subsubkey
objReg.EnumValues HKLM, KeyPath & "\" & subkey & "\" & subsubkey, arrSubValuenames, arrSubValuetypes
For I = 0 to UBound(arrSubValuenames)
Select Case arrsubvaluetypes(I)
Case REG_SZ
data_type = "String"
objReg.GetStringValue HKLM, Keypath & "\" & subkey & "\" & subsubkey, arrsubvaluenames(I), data_value
Case REG_EXPAND_SZ
data_type = "Expanded String"
objReg.GetExpandedStringValue HKLM, Keypath & "\" & subkey & "\" & subsubkey, arrsubvaluenames(I), data_value
Case REG_BINARY
data_type = "Binary"
objReg.GetBinaryValue HKLM, Keypath & "\" & subkey & "\" & subsubkey, arrsubvaluenames(I), data_value
data_value = ""
'For J = 0 to UBound(binary_array)
'data_value = data_value & binary_array(J) & " "
'Next
Case REG_DWORD
data_type = "DWORD"
objReg.GetDWORDValue HKLM, Keypath & "\" & subkey & "\" & subsubkey, arrsubvaluenames(I), data_value
Case REG_MULTI_SZ
data_type = "Multi String"
objReg.GetMultiStringValue HKLM, Keypath & "\" & subkey & "\" & subsubkey, arrsubvaluenames(I), data_value
data_value = ""
'For J = 0 to UBound(string_array)
'data_value = data_value & string_array(J) & " | "
'Next
End Select
StdOut.Writeline " Value: " & arrsubvaluenames(I) & " Type= " & data_type & " value = " & data_value
Next
Next
Next
I would prefer writing the code in java if that is easier. I know this is probably very simple and would appreciate any help?
I need help writing a java script.
My objective is to capture information under this key location. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers.
I originally wrote a VBScript to capture the information. However, I havent made any progress once it failed to capture multi-string and binary values in the subkeys.
(Printer.vbs below)
Const HKLM = &H80000002
Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_MULTI_SZ = 7
strComputer = "."
Set StdOut = WScript.StdOut
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
KeyPath = "SYSTEM\CurrentControlSet\Control\Print\Printers"
objReg.EnumKey HKLM, KeyPath, arrSubKeys
For Each Subkey in arrSubKeys
StdOut.WriteLine "Key: " & subkey
objReg.EnumValues HKLM, KeyPath & "\" & subkey, arrValuenames, arrValuetypes
For I = 0 to UBound(arrValuenames)
Select Case arrvaluetypes(I)
Case REG_SZ
data_type = "String"
Case REG_EXPAND_SZ
data_type = "Expanded String"
Case REG_BINARY
data_type = "Binary"
Case REG_DWORD
data_type = "DWORD"
Case REG_MULTI_SZ
data_type = "Multi String"
End Select
StdOut.Writeline " Value: " & arrvaluenames(I) & " Type= " & data_type
Next
objReg.Enumkey HKLM, KeyPath & "\" & subkey, arrSubSubKeys
For Each SubSubkey in arrSubSubkeys
StdOut.WriteLine " Subkey: " & subsubkey
objReg.EnumValues HKLM, KeyPath & "\" & subkey & "\" & subsubkey, arrSubValuenames, arrSubValuetypes
For I = 0 to UBound(arrSubValuenames)
Select Case arrsubvaluetypes(I)
Case REG_SZ
data_type = "String"
objReg.GetStringValue HKLM, Keypath & "\" & subkey & "\" & subsubkey, arrsubvaluenames(I), data_value
Case REG_EXPAND_SZ
data_type = "Expanded String"
objReg.GetExpandedStringValue HKLM, Keypath & "\" & subkey & "\" & subsubkey, arrsubvaluenames(I), data_value
Case REG_BINARY
data_type = "Binary"
objReg.GetBinaryValue HKLM, Keypath & "\" & subkey & "\" & subsubkey, arrsubvaluenames(I), data_value
data_value = ""
'For J = 0 to UBound(binary_array)
'data_value = data_value & binary_array(J) & " "
'Next
Case REG_DWORD
data_type = "DWORD"
objReg.GetDWORDValue HKLM, Keypath & "\" & subkey & "\" & subsubkey, arrsubvaluenames(I), data_value
Case REG_MULTI_SZ
data_type = "Multi String"
objReg.GetMultiStringValue HKLM, Keypath & "\" & subkey & "\" & subsubkey, arrsubvaluenames(I), data_value
data_value = ""
'For J = 0 to UBound(string_array)
'data_value = data_value & string_array(J) & " | "
'Next
End Select
StdOut.Writeline " Value: " & arrsubvaluenames(I) & " Type= " & data_type & " value = " & data_value
Next
Next
Next
I would prefer writing the code in java if that is easier. I know this is probably very simple and would appreciate any help?