Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query that reads the registry

Status
Not open for further replies.

pbanacos

IS-IT--Management
Apr 21, 2006
34
0
0
US
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?
 
First, java is not javascript. If you truly want to write java code for this you need a different forum.
If you want javascript there is the limitation that javascript is a client-side script but is not normally able to interact with the operating system side of the client.
To allow interaction with the OS from javascript and the web browser you have to use ActiveX which means it will work only with IE browsers and that it will trigger ActiveX warnings to the client that will require them to allow the action to occur.

Another option would be to use .HTA files rather than .htm.
HTA is HTML for Applications and is IE supported. A .HTA file on the clients computer will run with the rights of the user on that device and can access local drives, mapped network drives, the registry, etc, within the rights of the currently logged in user.

Javascript code for accessing the registry will be very similar to your VBScript code. I would suggest searching for sample code in JScript rather than javascript as most of your examples are going to be provided by Microsoft. Or visit one of the Microsoft JScript newsgroups if you cannot find help here.




Paranoid? ME?? Who wants to know????
 
It appears that the VBScript is a Windows Scripting Host script, and Javascript (actually JScript) will work fine with that. Javascript can be used in several different environments (WSH, client-side browser scripting, ASP, plus other custom scripting environments), but is most often seen in browsers as client-side scripting.

Converting your VBScript to Javascript won't change what it can do, just how it does the same thing. I'd advise you work with what you have to get the results you want rather than reinventing the script in another language, working out the bugs created in translation, and then trying to add in what the original is missing.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top