- You are here:
- Home
- CodeXchange
- All
- PowerBuilder
- A "Get Default Browser" Function
A "Get Default Browser" Function
- John Fauss
- Code Author
- Offline
Less
More
- Posts: 7
2 years 7 months ago #411
by John Fauss
This message has an attachment file.
John Fauss created the code: A "Get Default Browser" Function
A question was recently posted in the Q&A Forum about the Static HyperLink control, stating it would always open Internet Explorer to display the URL instead of the user’s default browser. My suggested solution was to use instead a normal StaticText control configured to appear like a Static HyperLink control and place code in the Clicked event of the StaticText control to issue a PowerScript Run function for the user’s default browser and pass to it the desired URL.
I thought it would be an interesting challenge to determine the path and name of your default browser’s executable – and this example application is the result. It was written using PB 2017.
There are numerous suggestions on the web on how to find the path and name of the default browser by interrogating the Windows Registry, but for various reasons I found them to be either out-of-date, incorrect in a Windows 10/11 system, or otherwise lacking. Eventually, I figured out a more reliable method for accomplishing this and created a PowerScript global function to implement the steps.
The f_GetDefaultBrowser global function object is the result. The code is generously commented and uses only the PowerScript RegistryGet function to access keys and values in the Windows Registry. The trick, of course, is determining exactly what information needs to be retrieved from the Windows Registry. If needed, this global function can be exported, then imported into an earlier version of PowerBuilder as long as the RegistryGet PowerScript function is available. I’ve verified that RegistryGet is available in PB 9, and it may be available even earlier.
I’ve noticed during testing that in some operating environments, the Static HyperLink control does indeed start up your default browser. I don’t know why it works in some operating environments and not in others.
My ability to test under different operating environments is limited, so I cannot guarantee the function will work successfully under all conditions. It has worked correctly for me in all of the tests I’ve performed to date. If you happen to encounter a scenario where it does not work, please let me know by providing a response to this post. Enjoy!
I thought it would be an interesting challenge to determine the path and name of your default browser’s executable – and this example application is the result. It was written using PB 2017.
There are numerous suggestions on the web on how to find the path and name of the default browser by interrogating the Windows Registry, but for various reasons I found them to be either out-of-date, incorrect in a Windows 10/11 system, or otherwise lacking. Eventually, I figured out a more reliable method for accomplishing this and created a PowerScript global function to implement the steps.
The f_GetDefaultBrowser global function object is the result. The code is generously commented and uses only the PowerScript RegistryGet function to access keys and values in the Windows Registry. The trick, of course, is determining exactly what information needs to be retrieved from the Windows Registry. If needed, this global function can be exported, then imported into an earlier version of PowerBuilder as long as the RegistryGet PowerScript function is available. I’ve verified that RegistryGet is available in PB 9, and it may be available even earlier.
I’ve noticed during testing that in some operating environments, the Static HyperLink control does indeed start up your default browser. I don’t know why it works in some operating environments and not in others.
My ability to test under different operating environments is limited, so I cannot guarantee the function will work successfully under all conditions. It has worked correctly for me in all of the tests I’ve performed to date. If you happen to encounter a scenario where it does not work, please let me know by providing a response to this post. Enjoy!
This message has an attachment file.
Please log in or register to see it.
Please Log in or Create an account to join the conversation.
- John Fauss
- Code Author
- Offline
Less
More
- Posts: 7
2 years 7 months ago - 2 years 5 months ago #414
by John Fauss
John Fauss replied the code: A "Get Default Browser" Function
That's very good to know. Thank you for calling this to everyone's attention! This function can also be used to start the user's default browser in conditions other than by emulating a static hyperlink control (a command button, for example), since the PB Inet object has been designated as "obsolete".
Last Edit: 2 years 5 months ago by John Fauss.
Please Log in or Create an account to join the conversation.
- * Appeon *
- Offline
Less
More
- Posts: 159
2 years 7 months ago #413
by * Appeon *
* Appeon * replied the code: A "Get Default Browser" Function
The bug of Static HyperLink control not using the user's default browser has been fixed in PowerBuilder 2019.
Please Log in or Create an account to join the conversation.
Moderators: Appeon Administrator