Skip to content
⌘ NSIS Forum Archive

How to link a label to open web page in unenvated process

10 posts

meoit#edited

How to link a label to open web page in unenvated process

Hi guys!

I am trying add label to left-bottom at morden.exe-105:

CONTROL "", 2019, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE, 50, 201, 45, 10

My install is elevated process.
But it is not working.

Code:

Unicode true
!include "MUI2.nsh"
Page Custom Page1
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_LANGUAGE English
Var /GLOBAL Arial8_Normal_U
Var /GLOBAL LB_Link
Function Page1
    CreateFont $Arial8_Normal_U 'Arial' '8.25' '400' /UNDERLINE
    nsDialogs::Create 1044
    Pop $R0
    ${If} $R0 == error
        Abort
    ${EndIf}
    GetDlgItem $LB_Link $HWNDPARENT 2019
    SendMessage $LB_Link ${WM_SETFONT} $Arial8_Normal_U 0
    SendMessage $LB_Link ${WM_SETTEXT} 0 'STR:Text-to-google'
    SetCtlColors $LB_Link FE0000 transpanrent
    GetFunctionAddress $R0 GO_HOMEPAGE
    nsDialogs::OnClick $LB_Link $R0
    nsDialogs::Show
FunctionEnd
Function GO_HOMEPAGE
    ShellExec 'open' 'http://google.com'
FunctionEnd
Section
SectionEnd 
Anders#
Have you tried adding a MessageBox to GO_HOMEPAGE to make sure it is called correctly?

nsDialogs::OnClick might only work for nsDialogs created controls and it might not work for static controls. Also, nsDialogs has a link control you can use but it only works in a custom page.
Anders#
Then you can't use nsDialogs onClick handling for non-nsDialogs controls. There is a ButtonEvent plug-in on the wiki but I don't know if it works on static controls.
meoit#
Thank Anders.

I tried ButtonEvent plug-in on Win10 x64, Static Label
Result, not working 🙁 (but Button, working fine).
r2du-soft#
Originally Posted by meoit View Post
Thank Anders.

I tried ButtonEvent plug-in on Win10 x64, Static Label
Result, not working 🙁 (but Button, working fine).


hello
try this:

Unicode true 

!include "MUI2.nsh"

Page Custom Page1 
!insertmacro MUI_PAGE_COMPONENTS 
!insertmacro MUI_PAGE_DIRECTORY 
!insertmacro MUI_LANGUAGE English 

Var Arial8_Normal_U 
Var Link_WebSite 

Function Page1 

nsDialogs::Create 1044 
Pop $R0 
${If} $R0 == error 
    Abort 
${EndIf} 

${NSD_CreateLink} 50 201 85 16 "Text-to-google"
Pop $Link_WebSite
;------------
CreateFont $Arial8_Normal_U 'Arial' '9.25' '400' /UNDERLINE 
SendMessage $Link_WebSite ${WM_SETFONT} $Arial8_Normal_U 0 
;------------
${NSD_OnClick} $Link_WebSite GO_HOMEPAGE

nsDialogs::Show 
FunctionEnd 

Function GO_HOMEPAGE 
	ExecShell "open" "http://google.com" SW_SHOWNORMAL
FunctionEnd 

Section 

SectionEnd  
Anders#
Try this new plug-in.

with this code

Unicode True
RequestExecutionLevel User
XPStyle On ; SysLink
PESubsysVer 5.1 ; SysLink is XP+
BrandingText ""
Name "WndEvent test"
Caption "$(^Name)"
SubCaption 4 " "
Section
SectionEnd
Page InstFiles "" OnInstFilesShow
!include nsDialogs.nsh
Function OnInstFilesShow
FindWindow $2 "#32770" "" $hWndParent
StrCpy $0 ""
loop: FindWindow $0 "" "" $2 $0
ShowWindow $0 0 ; Hide controls we don't care about
IntPtrCmpU 0 $0 "" loop loop
WndEvent::CreateWindow "SysLink" 'Hello <A HREF="http://example.com">World</A>' ${WS_CHILD}|${WS_VISIBLE} ${WS_EX_TRANSPARENT} 0u 0u 100u 12u "PAGE"
Var /Global syslink
Pop $syslink
GetFunctionAddress $1 SysLinkHandler
WndEvent::AddHandler "NOTIFY" "$syslink>PARENT" $1
WndEvent::CreateWindow "SysLink" '<A HREF="http://example.net">Link2</A>' ${WS_CHILD}|${WS_VISIBLE} 0 65u 145u 100u 12u $hWndParent
Var /Global syslink2
Pop $syslink2
GetFunctionAddress $1 SysLinkHandler
WndEvent::AddHandler "NOTIFY" "$hWndParent" $1
FunctionEnd
!define /IfNDef NM_CLICK -2
!define /IfNDef NM_RETURN -4
Function SysLinkHandler
${If} $2 = ${NM_CLICK}
${OrIf} $2 = ${NM_RETURN}
    ${If} $syslink Z= $3
    ${OrIf} $syslink2 Z= $3
        ExecShell "" "http://example.com"
    ${EndIf}
${EndIf}
FunctionEnd 
meoit#
Thanks Anders.

I see message:

Warning: This file type may contain malicious code. By executing it, your system may be compromised.

What can I do?.
Anders#
Originally Posted by meoit View Post
I see message:

Warning: This file type may contain malicious code. By executing it, your system may be compromised.

What can I do?.
I assume you are talking about anti-virus? Upload to VirusTotal and you should see that it is mostly clean. Then uninstall that anti-virus application...
T.Slappy#
What about using the Linker plug-in? https://nsis.sourceforge.io/Linker_plug-in

It is designed exactly for this purpose and it is really easy to use...