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

getting registry key names 1

Status
Not open for further replies.

cornboy88

Programmer
Jan 16, 2002
59
US
I am trying to read the the names of registry keys under(HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\).
I can get them using regobj.dll, but i would like to use WSH to get them. Any ideas?
 
WshShell.Run("regedit /e /a "& tempFileName &" HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\", 7, true)

Will export all the keys to a text file, then parse the file for the info you require
 
dude,

its much easier:

Function RegKeyExists(key)
Dim keyExists,scrap,shell
Set shell=CreateObject("WScript.Shell")
keyExists=true

On Error Resume Next
scrap=shell.RegRead(key)
If Err.Number<>0 Then
RegKeyExists=0
If Left(Err.Description,1)<>&quot;I&quot; Then RegKeyExists=1
Err.Clear
Else
RegKeyExists=-1
End If
On Error Goto 0
End Function

then,

If RegKeyExists(&quot;HKEY_LOCAL_MACHINE\SOFTWARE\<some_Key\value>&quot;) Then
somevar=shell.RegRead &quot;HKEY_LOCAL_MACHINE\SOFTWARE\<some_key\value>&quot;)
end if
 
hi cornboy88
I have a very similar task and the answers you got seem
not to work. The first one does not work, because the
regedit.exe is not in WINNT\system, which is in the default
PATH variable (my script must work with all default), and
the second is imho no answer to the question.
I'd expect that there is a method to get an array of all the
keys under a specified key whithout knowing their names.
Have you got an answer to this? If so, I'd appreciate to
get it.
Thanx
Peter
 
Code below

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = &quot;.&quot;
Set StdOut = WScript.StdOut

Set oReg=GetObject(&quot;winmgmts:{impersonationLevel=impersonate}!\\&quot; &_
strComputer & &quot;\root\default:StdRegProv&quot;)

strKeyPath = &quot;SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\&quot;
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

For Each subkey In arrSubKeys
msgbox subkey
Next


Taken from Technet scripting

link for that is


Regards
Steve
Regards
Steve Friday
 
Here is What I did:

Dim f1 'fso info
Dim sTest 'string used to test
Dim sMyPos 'string used for the name
Dim sMyPos1 'string used for the name
Dim iNum 'number for length of string
Dim sData 'holds the display name
Dim sFinal 'end result of loop

Dim oWS : Set oWS = CreateObject(&quot;WScript.Shell&quot;)
Dim oFSO : Set oFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)

oWS.Run &quot;regedit /e /a tempfile.txt HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall&quot;, 0, true

on error resume next
'WScript.Sleep 100

Set f1 = ofso_OpenTextFile(&quot;.\tempfile.txt&quot;, 1, True)


Do While Not f1.AtEndOfStream
sTest = f1.ReadLine
If InStr(1, sTest, &quot;[HKEY_LOCAL_MACHINE&quot;, 1) then
sMyPos = Mid(sTest, InstrRev(sTest, &quot;\&quot;, -1, 1))
iNum = Len(sMyPos)
sMyPos1 = Left(sMyPos, iNum - 1)
'msgbox sMyPos1
sData = oWs.RegRead(&quot;HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall&quot; & sMyPos1 & &quot;\DisplayName&quot;)

If err <> 0 then
err.clear
Else
sFinal = sFinal & sData & VbCrLf
End If
End If
Set sMyPos = nothing
Loop
msgbox sFinal

f1.close

'use this so i can see all of my results
Set f1 = ofso_OpenTextFile(&quot;.\tempfile.txt&quot;, 2, True)
f1.writeline sfinal
f1.close

WScript.Quit

Thanks for all of the help.
cornboy88
[noevil]
 
You also could use the RegObj.dll that can be downloaded from Microsoft (google for regobji.exe or so).
The code looks like this (just a short example that lists all dial up connections, so you have to do some extra work):

Dim objRegistry, objRegKey
Set objRegistry = CreateObject(&quot;RegObj.Registry&quot;)
Set objRegKey = objRegistry.RegKeyFromString(&quot;\HKEY_CURRENT_USER\RemoteAccess\Profile\&quot;)
For Each objRegKey In objRegKey.SubKeys
WScript.Echo(objRegKey.name)
Next
 
Sorry for that offtopic above, I have mixed some forum threads. I gave you exact that solution you didn't want ;-) but maybe it helps someone other.

Have fun and a nice day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top