Skip to content
⌘ NSIS Forum Archive

How can I run a file?

2 posts

Coby#

How can I run a file?

I use an HTML file in NSIS how can I execute a file when I click on a link or a button.

# Details
Name "Html Test"
OutFile "Html Test.exe"
InstallDir "$TEMP"
# Compress 
SetCompressor /SOLID /FINAL lzma
# RUN
RequestExecutionLevel user
# HIDE # SHOW
ShowInstDetails hide
ShowInstDetails nevershow
XPStyle on
# INCLUDES
!include "MUI2.nsh"
!include "WinCore.nsh"
!include "nsDialogs.nsh"
!include "LogicLib.nsh"
!include "WinMessages.nsh"
!include "FileFunc.nsh"
# Icon & Stye
BrandingText /TRIMRIGHT " "
# Page
!define MUI_CUSTOMFUNCTION_GUIINIT "onGuiInit"
Page Custom "WelcomePageShow"
Page instfiles ""
# ENGLISH
!insertmacro MUI_LANGUAGE "English"
# onInit
Function .onInit
  CreateDirectory "$EXEDIR"
  FileOpen $0 "$EXEDIR\Index.html" w
  FileWrite $0 "<html>"
  FileWriteByte $0 "10"
  FileWriteByte $0 "13"
  FileWrite $0 '<body link="#0C6E97">'
  FileWriteByte $0 "10"
  FileWriteByte $0 "13"
  FileWrite $0 '<a href="">Click My Link</a>'
  FileWriteByte $0 "10"
  FileWriteByte $0 "13"
  FileWrite $0 "</body>"
  FileWriteByte $0 "10"
  FileWriteByte $0 "13"
  FileWrite $0 "</html>"
  FileClose $0
FunctionEnd
Function "onGuiInit"
  # System::Call user32::SetWindowLong(i$HWNDPARENT,i-16, 0x9480084C) i.R0
  GetDlgItem $R0 $HWNDPARENT 1034
  ShowWindow $R0 ${SW_HIDE}
  GetDlgItem $R0 $HWNDPARENT 1035
  ShowWindow $R0 ${SW_HIDE}
  GetDlgItem $R0 $HWNDPARENT 1036
  ShowWindow $R0 ${SW_HIDE}
  GetDlgItem $R0 $HWNDPARENT 1037
  ShowWindow $R0 ${SW_HIDE}
  GetDlgItem $R0 $HWNDPARENT 1038
  ShowWindow $R0 ${SW_HIDE}
  GetDlgItem $R0 $HWNDPARENT 1039
  ShowWindow $R0 ${SW_HIDE}
  GetDlgItem $R0 $HWNDPARENT 1256
  ShowWindow $R0 ${SW_HIDE}
  GetDlgItem $R0 $HWNDPARENT 1028
  ShowWindow $R0 ${SW_HIDE}
  System::Call user32::GetSystemMetrics(i0)i.r1
  System::Call user32::GetSystemMetrics(i1)i.r2
  IntOp $1 $1 - 646
  IntOp $1 $1 / 2
  IntOp $2 $2 - 401
  IntOp $2 $2 / 2
  System::Call user32::MoveWindow(i$HWNDPARENT,i$1,i$2,i646,i401,1)
  SetCtlColors $HWNDPARENT "0x666666" "0xFFFFFF"
FunctionEnd
# WELCOME 
Function "WelcomePageShow"
  # ...:: variables ::... #
 
  var /GLOBAL DIALOG
  var /GLOBAL RTF_TOOLBOX
  GetDlgItem $0 $HWNDPARENT 1
  ShowWindow $0 ${SW_HIDE}
  GetDlgItem $0 $HWNDPARENT 2
  ShowWindow $0 ${SW_HIDE}
  GetDlgItem $0 $HWNDPARENT 3
  ShowWindow $0 ${SW_HIDE}
  GetDlgItem $0 $HWNDPARENT 1990
  ShowWindow $0 ${SW_HIDE}
  GetDlgItem $0 $HWNDPARENT 1991
  ShowWindow $0 ${SW_HIDE}
  GetDlgItem $0 $HWNDPARENT 1992
  ShowWindow $0 ${SW_HIDE}
  System::Call "user32::SetWindowPos(i$HWNDPARENT,i,i,i,i 646,i 401,i 0x16)"
  nsDialogs::Create /NOUNLOAD 1044
  Pop $DIALOG
  ${If} $DIALOG == error
   Abort
  ${EndIf}
  System::Call "user32::MoveWindow(i$DIALOG,i0,i0,i 646,i 401,i0)"
  SetCtlColors $DIALOG "0x666666" "0xFFFFFF"
  SendMessage $HWNDPARENT ${WM_SETTEXT} 0 "STR:$(^Name)"
  # Toolbox #
  System::Call `kernel32::GetModuleHandle(i 0) i.R3`
  System::Call 'User32::CreateWindowEx(i0,t"STATIC",i0,i0x50020100,i10,i0,i656,i400,i$Dialog,i1130,i0,i0)i.R1'
  Strcpy $RTF_TOOLBOX $R1
  WebCtrl::ShowWebInCtrl $RTF_TOOLBOX "$EXEDIR\index.html"
  System::Call "user32::SetDlgItemText(i$HWNDPARENT,i1,ts)" "ÎŇ˝ÓĘÜ(&I)"
  nsDialogs::Show
FunctionEnd
Section 
SectionEnd
Function .OnGuiEnd
FunctionEnd 
Anders#
What have you tried so far?

Also, how is colors and hidden controls related to this? I have told you so many times, post MINIMAL examples.