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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Unknown RegKeys 2:nd level

Status
Not open for further replies.

dukkse

Technical User
Oct 15, 2003
42
US
Hey!!

I am trying to get information from the registry, but the problem is that the key I am looking for is 2 levels deep of random named keys, so I need to do a "For each subkey
" and inside that For, another "For each subkey" before I den can read out the description.
Thing is, I can get the info from the first keys, but I can't get down to the second keys.
Please help

Thx
Daniel

Here is the code:
The key I want is for a tape station installed on a W2003 server.
*********************************************************
const HKEY_LOCAL_MACHINE = &H80000002
Set wshshell = WScript.CreateObject("WScript.Shell")

strComputer = wshshell.regread("HKLM\SYSTEM\CURRENTCONTROLSET\CONTROL\COMPUTERNAME\COMPUTERNAME\COMPUTERNAME")

Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\Enum\SCSI"
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

On Error Resume next
For Each subkey In arrSubKeys
strKeyPath = "SYSTEM\CurrentControlSet\Enum\SCSI" & subkey
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath1, arrSubKeys1
For Each sub2key In arrSubKeys1
MsgBox sub2key
MsgBox "Key: " & wshshell.regread("HKLM\SYSTEM\CurrentControlSet\Enum\SCSI\" & subkey & sub2key & "\DeviceDesc")
Next
Next

MsgBox "Done
 
Here is a sample that might help you. I use this script to enumerate through the registry and change the Exchange Server data for a user. Does exactly what you are looking for.

'Registry edit script

'By Mark MacLachlan, The Spider's Parlor
'(c)2004 All rights Reserved
'Modifies the registry to change exchange server names.
'Notes: Modify the path and server variables for your environment.



On Error Resume Next

const HKEY_CURRENT_USER = &H80000001

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_

".\root\default:StdRegProv")

Set StdOut = WScript.StdOut

strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\"

oReg.EnumKey HKEY_CURRENT_USER, strKeyPath, arrSubKeys

For Each subkey In arrSubKeys
expStrKeyPath = strKeyPath & subkey & "\"
oReg.EnumKey HKEY_CURRENT_USER, expStrKeyPath, arr2SubKeys

For Each subkey2 In arr2SubKeys

expStrKeyPath2 = expStrKeyPath & subkey2
If Right(expStrKeyPath2,32) = "13dbb0c8aa05101a9bb000aa002fc45a" Then

Dim Path
Path = "HKCU\" & expStrKeyPath2 & "\"
Set WSHShell = Wscript.CreateObject("WScript.Shell")
ServerName = "NewServerName"
OldServer = "OldServerName"

'this fills the sub key with the value of new server and specifies that it is a regular string

KeyExist = WSHShell.RegRead(path & "001e6608")

If KeyExist = ServerName Then

Wscript.Quit

ElseIf Ucase(KeyExist) <> OldServerName Then

MsgBox "Unexpected Exchange Settings. Please contact the help desk"

Wscript.Quit

ElseIf Ucase(KeyExist) = OldServerName Then

WSHShell.RegWrite path & "001e6608",ServerName,"REG_SZ"

WSHShell.RegWrite path & "001e6602",ServerName,"REG_SZ"

End If


If err then

msgbox "Error Encountered Changing Exchange Server Name" & vbCrLf & "Please contact the help desk."

else

Wscript.Quit

End if
Wscript.Quit
End If
Next
Next






I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Well, it kinda helped me. I did like this in the end:

For Each subkey In arrSubKeys

strKeyPath1 = strKeyPath & "\" & subkey
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath1, arr2SubKeys

For Each sub2key In arr2SubKeys
subkeyPath2 = strKeyPath & "\" & subkey & "\" & sub2Key
if wshshell.regread("HKLM\" & subkeyPath2 & "\Class") = "TapeDrive" Then MsgBox wshshell.regread("HKLM\" & subkeyPath2 & "\FriendlyName")
Next
Next


Thanks guys..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top