Registry again...

I think this question may have been asked for many times, but please allow me to ask again.
I am developing a software using VB, but I am extremely new to it. I need to invoke Netscape and IE to preview a web page from my programme. I used       "AppId = Shell()" and "AppActivate AppId" and it worked. However, I cannot get the path of Netscape and IE from the registry. What I did was to hard-code the path, which is not acceptable.
Can anyone tell me the way to read registry values? More specifically, could you tell me the key to find Netscape and IE install locations and give me sample code of reading them?
Thanks in advance.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I don't know which OS you are using. I found out the key in NT only. But I think that  it may be no difficult in 95/98

netscape : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\CurrentVersion\App Paths\Netscape.exe\Path


to read the registry

Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002

Public Const KEY_ALL_ACCESS = &H3F
Public Const SUCCESS = &H0

Public Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hkey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hkey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long         ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hkey As Long) As Long

Dim lType As Long
Dim hkey As Long
Dim lReturnCode As Long
Dim sPath As string
sPath = space(255)
lReturnCode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\Microsoft\windows\CurrentVersion\App Paths\Netscape.exe", 0&, KEY_ALL_ACCESS, hkey)
If lReturnCode = SUCCESS Then
    Call RegQueryValueEx(hkey, "Path", 0&, lType, sPath, 255)
End If
sPath = left$(sPath, instr(sPath,chr(0)) -1)

Call RegCloseKey(hkey)

Same procedure to get the IE path
in IE, using the registry is much better

ylyipAuthor Commented:
Sorry, the code failed. I include your codes into my programme, when it runs, illegal opertion was reported.
I am using Chinese Windows 98 and VB 5.0.
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Try using this function with your URL (i.e. "") as the first parameter. This will execute whatever program is set up as your default browser application.

If the execution was successful the return value is a empty string, otherwhise it contains a error message.

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Function Run(strFilePath As String, Optional strParms As String, Optional strDir As String) As String
  Const SW_SHOW = 5
  'Run the Program and Evaluate errors
  Select Case ShellExecute(0, "Open", strFilePath, strParms, strDir, SW_SHOW)
  Case 0
    Run = "Insufficent system memory or corrupt program file"
  Case 2
    Run = "File not found"
  Case 3
    Run = "Invalid path"
  Case 5
    Run = "Sharing or Protection Error"
  Case 6
    Run = "Seperate data segments are required for each task"
  Case 8
    Run = "Insufficient memory to run the program"
  Case 10
    Run = "Incorrect Windows version"
  Case 11
    Run = "Invalid program file"
  Case 12
    Run = "Program file requires a different operating system"
  Case 13
    Run = "Program requires MS-DOS 4.0"
  Case 14
    Run = "Unknown program file type"
  Case 15
    Run = "Windows program does not support protected memory mode"
  Case 16
    Run = "Invalid use of data segments when loading a second instance of a program"
  Case 19
    Run = "Attempt to run a compressed program file"
  Case 20
    Run = "Invalid dynamic link library"
  Case 21
    Run = "Program requires Windows 32-bit extensions"
  Case Else
    Run = ""
  End Select

End Function

ylyipAuthor Commented:
Torus, after changing "any" to "string" in your code, the registry values were obtained sucessfully. I would like to give you the points, could you post an answer again? (I cannot find "accept a comment as an answer", do you know where it can be found?)

Vbmaster, thanks for your help but I want my users to be able to preview their pages in both browsers, not only the default browser.
Text as above.

Maybe I posted the answer, so accept comment as answer option is disappeared.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ok. Sorry for the mistake. Actually, you may not need to chanage "any" to "string"

The call should be

Call RegQueryValueEx(hkey, "Path", 0&, lType, BYVAL sPath, 255)

I missed the important Keyword.

if your program needs to use the RegQueryValueEx to query another type of data and you change "any" to "string", it will not work. e.g if the return path is long,

Call RegQueryValueEx(hkey, "Path", 0&, lType, lPath, 255)

if you keep the "any", you can return the value that you want.

Surely, if you just query the string, doesn't matter in this case
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.