Old 9th October 2015, 09:11   #1
stefque
Junior Member
 
Join Date: Oct 2015
Posts: 1
Detecting default browser on Windows 8

Hi guys,

I have trouble detecting the default browser on Win 8.1 Pro, but it goes the same for Win 8 also.
I have a script that worked just fine on Win 7:

code:
FileOpen $0 "$PLUGINSDIR\dummy.htm" "w"
FileClose $0
System::Call "Shell32::FindExecutable(t '$PLUGINSDIR\dummy.htm', i 0, t .r1)"
${StrLoc} $0 $1 "chrome.exe" ">"
${If} $0 == ""
${StrLoc} $0 $1 "firefox.exe" ">"
${If} $0 == ""
${StrLoc} $0 $1 "iexplore.exe" ">"
${If} $0 == ""
StrCpy $BR "00"
${Else}
StrCpy $BR "IE"
${EndIf}
${Else}
StrCpy $BR "FF"
${EndIf}
${Else}
StrCpy $BR "CH"
${EndIf}



This doesn't work on Windows above Win 7.



After this command:
code:
System::Call "Shell32::FindExecutable(t '$PLUGINSDIR\dummy.htm', i 0, t .r1)"

on Win 7 I can print $1 and get: "C:\Program Files\Internet Explorer\iexplore.exe"

but for some reason, on Win 8.1, I get: "C:\Windows\system32\OpenWith.exe" and I always get BR = "00", meaning that some other browser (other than GC, FF, IE) is the default browser.

Do you have any instructions, or code samples, that could help me overcome this Win 8 issue?

Best,
Stefan
stefque is offline   Reply With Quote
Old 9th October 2015, 10:32   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,309
There is no such thing as a default browser in Windows, a user can set FF to open .htm files, CH to open .html files, IE to open the HTTP protocol and Safari to open the HTTPS protocol if they wanted to. OpenWith.exe probably means the user has not chosen a default handler for .htm files yet. There are of course other browsers like Opera and Maxthon so you need to be able to handle BR = "00" anyway.

If you just want to open a .htm file or a URL you should just use ExecShell and not actually try to detect the browser.

If you look at http://blogs.msdn.com/b/oldnewthing/.../10641381.aspx you see that what they call the default browser is the application that handles the http protocol. You can use the same detection if you want:

Quote:
!define ASSOCSTR_COMMAND 1
!define ASSOCSTR_EXECUTABLE 2
!define ASSOCF_NOTRUNCATE 0x00000020
!define ASSOCF_REMAPRUNDLL 0x00000080
!define ASSOCF_NOFIXUPS 0x00000100
!define ASSOCF_ISPROTOCOL 0x00001000



System::Call 'SHLWAPI::AssocQueryString(i ${ASSOCF_NOTRUNCATE}|${ASSOCF_REMAPRUNDLL}|${ASSOCF_NOFIXUPS}|${ASSOCF_ISPROTOCOL}, i ${ASSOCSTR_COMMAND}, t "http", t "open", t.r1, *i ${NSIS_MAX_STRLEN})i.r0' ; WinXP is buggy is you don't force the open verb...
DetailPrint Command:hr=$0,string=$1

System::Call 'SHLWAPI::AssocQueryString(i ${ASSOCF_NOTRUNCATE}|${ASSOCF_REMAPRUNDLL}|${ASSOCF_NOFIXUPS}|${ASSOCF_ISPROTOCOL}, i ${ASSOCSTR_EXECUTABLE}, t "http", t "open", t.r1, *i ${NSIS_MAX_STRLEN})i.r0'
DetailPrint Executable:hr=$0,string=$1

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 9th October 2015, 10:50   #3
T.Slappy
Major Dude
 
T.Slappy's Avatar
 
Join Date: Jan 2006
Location: Slovakia
Posts: 548
Send a message via ICQ to T.Slappy
Try this simple code which is working for me (on all OSs):

PHP Code:
    Detect browser
    FileOpen 
$"$PLUGINSDIR\dummy.htm" "w"
    
FileClose $1
    
!ifdef IS_UNICODE
        System
::Call "Shell32::FindExecutableW(t '$PLUGINSDIR\dummy.htm', i 0, t .r1)"
    
!else
        
System::Call "Shell32::FindExecutableA(t '$PLUGINSDIR\dummy.htm', i 0, t .r1)"
    
!endif
    ${
DebugMsg"Your Default Browser is: $1" 

DebugMsg is simple MessageBox call.
What you need is to set symbol IS_UNICODE correctly: If you are using Unicode NSIS.

Cool looking installers with custom design: www.graphical-installer.com
Create Setup Pages easily: www.install-designer.com
Build installers in Visual Studio 2005-2019: www.visual-installer.com
or RAD Studio 2009, 2010, XE-10.4 Sydney: www.rad-installer.com
T.Slappy is offline   Reply With Quote
Old 9th October 2015, 12:13   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,309
Thumbs down

Quote:
Originally Posted by T.Slappy View Post
Try this simple code which is working for me (on all OSs).
This code is basically the same as the original, just a little broken! The OP is getting back a valid string so their system syntax is already correct!

Why invent a new Unicode define when we already have one?

Why hardcode A and W suffix when it is not required?

You should not use the t string type when forcing A/W.

Did you actually test on everything from Win95 to Win10? Win95RTM did not ship with a browser...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 9th October 2015, 15:41   #5
stass
Senior Member
 
Join Date: Nov 2012
Posts: 146
Anders
From your example, it turns out that something strange ... Windows 7 x32
Quote:
Executable:hr=-2147023741,string=
Completed
stass is offline   Reply With Quote
Old 9th October 2015, 17:00   #6
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,309
Quote:
Originally Posted by stass View Post
Anders
From your example, it turns out that something strange ... Windows 7 x32

Quote:
Executable:hr=-2147023741,string=
Completed
0x80070483 = No application is associated with the specified file for this operation.

There can probably be multiple reasons why this is returned. It is unlikely that your machine does not have a open verb for http but I guess it could happen. A more likely reason is that a shell extension is the handler and not a simple .exe file, this is completely legal, there is no guarantee that you can find the name of the .exe that will run when you ShellExecute something...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 10th October 2015, 06:46   #7
stass
Senior Member
 
Join Date: Nov 2012
Posts: 146
Got it ... ASSOCF_IS_PROTOCOL - in Win7 does not work ...

In Win7 x32 as possible :

System::Call 'SHLWAPI::AssocQueryString(i ${ASSOCF_NOTRUNCATE}|${ASSOCF_REMAPRUNDLL}|${ASSOCF_NOFIXUPS}, i ${ASSOCSTR_EXECUTABLE}, t ".htm", t "open", t.r1, *i ${NSIS_MAX_STRLEN})i.r0'

However, Win 10 x64 - it does not work ...
and :

System::Call 'SHLWAPI::AssocQueryString(i ${ASSOCF_NOTRUNCATE}|${ASSOCF_REMAPRUNDLL}|${ASSOCF_NOFIXUPS}|${ASSOCF_ISPROTOCOL}, i ${ASSOCSTR_EXECUTABLE}, t ".htm", t "open", t.r1, *i ${NSIS_MAX_STRLEN})i.r0'

and :

System::Call 'SHLWAPI::AssocQueryString(i ${ASSOCF_NOTRUNCATE}|${ASSOCF_REMAPRUNDLL}|${ASSOCF_NOFIXUPS}|${ASSOCF_ISPROTOCOL}, i ${ASSOCSTR_EXECUTABLE}, t "http", t "open", t.r1, *i ${NSIS_MAX_STRLEN})i.r0'

Result:
Quote:
Executable:hr=0,string=C:\Windows\system32\LaunchWinApp.exe
The only thing that happened:

!define ASSOCSTR_FRIENDLYAPPNAME 4
System::Call 'SHLWAPI::AssocQueryString(i ${ASSOCF_NOTRUNCATE}|${ASSOCF_REMAPRUNDLL}|${ASSOCF_NOFIXUPS}|${ASSOCF_ISPROTOCOL}, i ${ASSOCSTR_FRIENDLYAPPNAME}, t ".htm", t "open", t.r1, *i ${NSIS_MAX_STRLEN})i.r0'

Result:
Quote:
Command:hr=0,string=Microsoft Edge
How to get the full path to Microsoft Edge of function ?

Last edited by stass; 10th October 2015 at 08:32.
stass is offline   Reply With Quote
Old 10th October 2015, 09:55   #8
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,309
ASSOCF_IS_PROTOCOL is documented as Win8+ but XP did not care when I tested but you should of course only set it for URL protocols like HTTP, not on file extensions like .htm.

If the function returns 0 then it was successful but like I already said, it does not mean you can always get the name of the .exe. If Microsoft uses a generic launcher then that is the design they chose and there might not be a lot you can do about it.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 10th October 2015, 13:27   #9
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,309
Another thing you can try is to read from the registry under \SOFTWARE\Clients\StartMenuInternet ( https://msdn.microsoft.com/en-us/lib...=vs.85%29.aspx "This registration is deprecated as of Windows 7"). You must see if there is a default in HKCU and fall back to HKLM (On my machine I have not used the default applications applet in the control panel so I don't have a Clients key under HKCU!)

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump