?
Solved

Registry again...

Posted on 1999-11-03
7
Medium Priority
?
198 Views
Last Modified: 2010-05-02
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.
0
Comment
Question by:ylyip
  • 4
  • 2
7 Comments
 
LVL 2

Expert Comment

by:Torus
ID: 2182112
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

IE4 : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\IE4\Setup\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
0
 
LVL 2

Expert Comment

by:Torus
ID: 2182127
in IE, using the registry is much better

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\CurrentVersion\App
Paths\IEXPLORE.EXE\Path
0
 
LVL 1

Author Comment

by:ylyip
ID: 2182300
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.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 7

Expert Comment

by:Vbmaster
ID: 2182366
Try using this function with your URL (i.e. "http://www.altavista.com") 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


0
 
LVL 1

Author Comment

by:ylyip
ID: 2182379
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.
0
 
LVL 2

Accepted Solution

by:
Torus earned 400 total points
ID: 2183370
Text as above.


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

0
 
LVL 2

Expert Comment

by:Torus
ID: 2183418
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
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question