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

Searching registry

Status
Not open for further replies.

sfenx

Programmer
Feb 23, 2001
81
BE
I'm experimenting with the Windows Registry at the moment. I read the FAQ "Reading and Writing Registry Values" by Mike Lacey and a lot of other threads, but I still have some questions about the GetSetting/SaveSetting statement.
What I would like to do is check whether a program is installed (i.e. Word Reader) and get the setting of the directory where the program is installed so I can call it from there. The keyname in the registry is
Code:
HKEY_CURRENT_USER\Software\Microsoft\Word Viewer\8.0\Options[\code].
The name of the directory is stored in "PROGRAMDIR" -> "c:\program files\WordView".
I tryed several things, this was my last attempt :
[code]Debug.Print GetSetting(appname:="Word Viewer", Section:="HKEY_CURRENT_USER\Software\Microsoft\Word Viewer\8.0\Options", Key:="PROGRAMDIR")[\code]
I don't know what to put in the appname section of the statement. The MSDN lib says "String expression containing the name of the application or project whose key setting is requested.", but where can I find the exact name of the application ?
Hope someone can help me out here.
Sfenx 8-)
 
GetSetting/Savesetting only gives you access to a very small part of the registry.
You need to use API-calls. I pinched this from allapi.net (they seem to be down right now)


Const HKEY_CURRENT_CONFIG = &H80000005
Const HKEY_LOCAL_MACHINE = &H80000002
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, lpftLastWriteTime As Any) As Long
Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As Byte, lpcbData As Long) As Long
Private Sub Form_Paint()
'KPD-Team 1999
'URL: 'E-Mail: KPDTeam@Allapi.net
Dim hKey As Long, Cnt As Long, sSave As String
'Clear the form
Me.Cls
Me.Print "RegEnumKeyEx"
'Open a registry key
RegOpenKey HKEY_LOCAL_MACHINE, "Enum", hKey
Do
'Create a buffer
sSave = String(255, 0)
'Enumerate the keys
If RegEnumKeyEx(hKey, Cnt, sSave, 255, 0, vbNullString, ByVal 0&, ByVal 0&) <> 0 Then Exit Do
'Print the result to the form
Me.Print StripTerminator(sSave)
Cnt = Cnt + 1
Loop
'Close the registry key
RegCloseKey hKey
Me.Print vbCrLf + &quot;RegEnumValue:&quot;
'Open a new key
RegOpenKey HKEY_CURRENT_CONFIG, &quot;Display\Fonts&quot;, hKey
Cnt = 0
Do
'Create a buffer
sSave = String(255, 0)
'enumerate the values
If RegEnumValue(hKey, Cnt, sSave, 255, 0, ByVal 0&, ByVal 0&, ByVal 0&) <> 0 Then Exit Do
'pritn the results to the form
Me.Print StripTerminator(sSave)
Cnt = Cnt + 1
Loop
'Close the registry
RegCloseKey hKey
End Sub
'This function is used to stripoff all the unnecessary chr$(0)'s
Private Function StripTerminator(sInput As String) As String
Dim ZeroPos As Integer
'Search the first chr$(0)
ZeroPos = InStr(1, sInput, vbNullChar)
If ZeroPos > 0 Then
StripTerminator = Left$(sInput, ZeroPos - 1)
Else
StripTerminator = sInput
End If
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top