Page 1 of 1
Get Windows Internet Default Browser
Posted: Sat Nov 28, 2009 2:35 pm
by RASHAD
Windows XP,Vista,7 x86 - x64
Code: Select all
Procedure.s GetTempDirectory()
Protected WinTemp.s
WinTemp = Space(255)
GetTempPath_(255, WinTemp)
If Right(WinTemp, 1) <> "\" : WinTemp = WinTemp + "\" : EndIf
ProcedureReturn WinTemp
EndProcedure
Associatefile$ = Space(1024)
CreateFile(0,GetTempDirectory()+"test.html")
WriteString(0,"<HTML> <\HTML>")
CloseFile(0)
FindExecutable_("test.html",GetTempDirectory(),@Associatefile$)
MessageRequester("Default Internet Browser",GetFilePart(Associatefile$))
DeleteFile(GetTempDirectory()+"test.html")
Have fun
Re: Get Windows Internet Default Browser
Posted: Sat Nov 28, 2009 3:07 pm
by UserOfPure
(1) You can replace your entire GetTempDirectory procedure with the GetTemporaryDirectory() command.
(2) Your code just returns the app used to open HTML files -- it doesn't get the default browser as such (even though they're probably the same 99% of the time). For example, my default browser is Firefox, but my PC opens HTML files with Iexplore. So, running your code shows Iexplore as my default browser when it's not.
Re: Get Windows Internet Default Browser
Posted: Sat Nov 28, 2009 3:33 pm
by RASHAD
UserOfPure
Your first comment is much appreciated and I will use it
Your second about the Other 1% I will try to investigate it first
Then may be I will find a way to accommodate it
Thank you very much
Code: Select all
Associatefile$ = Space(1024)
CreateFile(0,GetTemporaryDirectory() +"test.html")
WriteString(0,"<HTML> <\HTML>")
CloseFile(0)
FindExecutable_("test.html",GetTemporaryDirectory(),@Associatefile$)
MessageRequester("Default Internet Browser",GetFilePart(Associatefile$))
DeleteFile(GetTemporaryDirectory()+"test.html")
Re: Get Windows Internet Default Browser
Posted: Sat Nov 28, 2009 8:34 pm
by Little John
Yesterday there already has been created
another thread that shows how to get the default internet browser on windows.
Regards, Little John
Re: Get Windows Internet Default Browser
Posted: Sat Nov 28, 2009 8:42 pm
by RASHAD
Sorry Little John
This is Tricks 'n' Tips Not Coding Ques.
If you have a tip of your own you must post it in a new thread
But if you have a comment on any one tip or a little modification you have to use post reply
Re: Get Windows Internet Default Browser
Posted: Sat Nov 28, 2009 8:56 pm
by ts-soft
RASHAD wrote:Sorry Little John
This is Tricks 'n' Tips Not Coding Ques.
If you have a tip of your own you must post it in a new thread
But if you have a comment on any one tip or a little modification you have to use post reply
The result of the other thread is what your title suggest.
Your result is the file to open html, but not the Internet Default Browser.
Greetings
Thomas
Re: Get Windows Internet Default Browser
Posted: Sat Nov 28, 2009 8:57 pm
by Little John
RASHAD wrote:Sorry Little John
This is Tricks 'n' Tips Not Coding Ques.
If you have a tip of your own you must post it in a new thread
But if you have a comment on any one tip or a little modification you have to use post reply
I just wanted to provide a link to the other thread with (almost) the same topic, so that later for people who are searching code it's easier to find what they are looking for.
Re: Get Windows Internet Default Browser[Updated]
Posted: Mon Nov 30, 2009 6:14 am
by RASHAD
I do't know when anyone will need to check for the Default Web Browser
But As UserOfPure pointed to in his post
This piece of code checks for the Real Default URL Browser
Tested on XP,Vista,Windows 7 x86 x64 For IE & FireFox Only
Code: Select all
lRetVal.i
sRemMachName.s
lTopLevelKey.i
lHKeyhandle.i
sKeyName.s
lhkey.i
sValueName.s
vValue.s
msg.s
;
#ERROR_NONE = 0
#KEY_WOW64_64KEY=$100
#KEY_WOW64_32KEY=$200
Procedure.l QueryValueEx(lhkey.l, szValueName.s)
Define.l cch, lrc, lType, lValue
Define.s sValue
Shared vValue
cch = 255
sValue = Space(255)
lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, 0, @cch)
Select lType
Case #REG_SZ
lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, @sValue, @cch)
If lrc = #ERROR_NONE
vValue = Left(sValue, cch-1)
Else
vValue = "Empty"
EndIf
Case #REG_DWORD
lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, @lValue, @cch)
If lrc = #ERROR_NONE
vValue = Str(lValue)
EndIf
Default
lrc = -1
EndSelect
ProcedureReturn lrc
EndProcedure
sRemMachName = ""
If OSVersion() >= 60 And OSVersion() < 70
lTopLevelKey = #HKEY_CLASSES_ROOT
sKeyName = "Http\Shell\Open\Command"
sValueName = ""
ElseIf OSVersion() >= 70 And OSVersion() < 100
lTopLevelKey = #HKEY_CURRENT_USER
sKeyName = "Software\Clients\StartMenuInternet"
sValueName = ""
EndIf
lRetVal = RegConnectRegistry_(sRemMachName, lTopLevelKey, @lHKeyhandle)
lRetVal = RegOpenKeyEx_(lHKeyhandle, sKeyName, 0,#KEY_READ|#KEY_WOW64_64KEY, @lhkey)
lRetVal = QueryValueEx(lhkey, sValueName)
RegCloseKey_(lhkey)
If lRetVal = 0
If FindString(vValue,"FIREFOX.EXE",1) Or FindString(vValue,"firefox.exe",1)
MessageRequester("Default Browser","FireFox",#MB_ICONINFORMATION)
ElseIf FindString(vValue,"IEXPLORE.EXE",1) Or FindString(vValue,"iexplore.exe",1)
MessageRequester("Default Browser","MS Internet Explorer",#MB_ICONINFORMATION)
Else
MessageRequester("Default Browser","Unknown",#MB_ICONINFORMATION)
EndIf
Else
msg = "An Error occured, Return value = " + Str(lRetVal)
MessageRequester("Error",msg, #MB_ICONERROR)
EndIf
Re: Get Windows Internet Default Browser
Posted: Mon Nov 30, 2009 8:04 pm
by rsts
Hi Rashad,
On my windows 7 64 bit there is no #HKEY_CURRENT_USER\Software\Clients
thus I get a -1 error.
Not a complaint, just letting you know
cheers
Re: Get Windows Internet Default Browser
Posted: Mon Nov 30, 2009 10:52 pm
by RASHAD
Hi rsts
Glad To hear from you
That is strange
Check the Next link And tell me what could be the cause
How To Register an Internet Browser Or E-mail Client With the Windows Start Menu
http://msdn.microsoft.com/en-us/librar ... .85).aspx
And with the real and good comments I am so happy
Back me up my friend
have a good day
Re: Get Windows Internet Default Browser
Posted: Tue Dec 01, 2009 12:29 am
by rsts
Hi Rashad,
For my win 7 installation there is no #HKEY_CURRENT_USER\Software\Clients -
But there is a #HKEY_LOCAL_MACHINE\Software\Clients\StartMenuInternet
which correctly returns
---------------------------
Default Browser
---------------------------
MS Internet Explorer
---------------------------
OK
---------------------------
it may be necessary to check #HKEY_CURRENT_USER\Software\Clients first and if none check
#HKEY_LOCAL_MACHINE\Software\Clients\StartMenuInternet.
That's the way it would appear to work on mine.
cheers
Re: Get Windows Internet Default Browser
Posted: Tue Dec 01, 2009 12:35 am
by RASHAD
Good
I will do it
Your wish is a command mate
Have a nice day
Re: Get Windows Internet Default Browser
Posted: Tue Dec 01, 2009 1:55 am
by RASHAD
Update
Code: Select all
lRetVal.i
sRemMachName.s
lTopLevelKey.i
lHKeyhandle.i
sKeyName.s
lhkey.i
sValueName.s
vValue.s
msg.s
;
#ERROR_NONE = 0
#KEY_WOW64_64KEY=$100
#KEY_WOW64_32KEY=$200
Procedure.l QueryValueEx(lhkey.l, szValueName.s)
Define.l cch, lrc, lType, lValue
Define.s sValue
Shared vValue
cch = 255
sValue = Space(255)
lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, 0, @cch)
Select lType
Case #REG_SZ
lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, @sValue, @cch)
If lrc = #ERROR_NONE
vValue = Left(sValue, cch-1)
Else
vValue = "Empty"
EndIf
Case #REG_DWORD
lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, @lValue, @cch)
If lrc = #ERROR_NONE
vValue = Str(lValue)
EndIf
Default
lrc = -1
EndSelect
ProcedureReturn lrc
EndProcedure
sRemMachName = ""
sValueName = ""
If OSVersion() >= 60 And OSVersion() < 70
lTopLevelKey = #HKEY_CLASSES_ROOT
sKeyName = "Http\Shell\Open\Command"
;sValueName = ""
ElseIf OSVersion() >= 70 And OSVersion() < 100
lTopLevelKey = #HKEY_CURRENT_USER
sKeyName = "Software\Clients\StartMenuInternet"
;sValueName = ""
EndIf
Check2:
lRetVal = RegConnectRegistry_(sRemMachName, lTopLevelKey, @lHKeyhandle)
lRetVal = RegOpenKeyEx_(lHKeyhandle, sKeyName, 0,#KEY_READ|#KEY_WOW64_64KEY, @lhkey)
lRetVal = QueryValueEx(lhkey, sValueName)
RegCloseKey_(lhkey)
If OSVersion() >= 70 And OSVersion() < 100 And lRetVal <> 0
lTopLevelKey = #HKEY_LOCAL_MACHINE
sKeyName = "Software\Clients\StartMenuInternet"
Goto Check2
EndIf
If lRetVal = 0
If FindString(vValue,"FIREFOX.EXE",1) Or FindString(vValue,"firefox.exe",1)
MessageRequester("Default Browser","FireFox",#MB_ICONINFORMATION)
ElseIf FindString(vValue,"IEXPLORE.EXE",1) Or FindString(vValue,"iexplore.exe",1)
MessageRequester("Default Browser","MS Internet Explorer",#MB_ICONINFORMATION)
Else
MessageRequester("Default Browser","Unknown",#MB_ICONINFORMATION)
EndIf
Else
msg = "An Error occured, Return value = " + Str(lRetVal)
MessageRequester("Error",msg, #MB_ICONERROR)
EndIf
Re: Get Windows Internet Default Browser
Posted: Thu Aug 09, 2012 10:54 am
by CONVERT
Thanks Rashad,
I used your first code:
Code: Select all
Procedure.s get_default_internet_browser ()
Define wresult$, wno_test, wftest$
wresult$ = Space(1024)
wftest$ = "test.html"
wno_test = CreateFile(#PB_Any,wftest$)
If wno_test <> 0
CloseFile(wno_test)
FindExecutable_(wftest$,GetCurrentDirectory(),wresult$)
DeleteFile(wftest$)
EndIf
ProcedureReturn Trim(wresult$)
EndProcedure
MessageRequester("",get_default_internet_browser ())