Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 5th March 2020, 13:05   #1
meoit
Member
 
Join Date: Oct 2014
Location: $DESKTOP
Posts: 99
Post Run elevated *.exe in non-elevated installer in the dual mode (SILENT/NORMAL)

My Installer have two mode to install: GUI and SILENT.

I want installer to run non-elevated process when user using GUI
AND
I want installer to run elevated process when user using SILENT.

But unsuccessful

This is code:

PHP Code:
Unicode true
RequestExecutionLevel user

!include 'MUI2.nsh'
!include 'x64.nsh'
!include 'WinVer.nsh'

Var /GLOBAL Var_Silent
Var /GLOBAL Var_Silent
;--------------------------------
;
General

  
;Name and file
  Name 
"Non-Elevated/Elevated Dual Mode Installer"
  
OutFile "TEST-DualMode.exe"

  
;Default installation folder
  InstallDir 
"$LOCALAPPDATA\Modern UI Test"

  
;Get installation folder from registry if available
  InstallDirRegKey HKCU 
"Software\Dual Mode Installer" ""

;--------------------------------
;Interface 
Settings

  
!define MUI_ABORTWARNING

;--------------------------------
;
Pages

  
!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\License.txt"
  
!insertmacro MUI_PAGE_COMPONENTS
  
!insertmacro MUI_PAGE_DIRECTORY
  
!insertmacro MUI_PAGE_INSTFILES

  
!insertmacro MUI_UNPAGE_CONFIRM
  
!insertmacro MUI_UNPAGE_INSTFILES

;--------------------------------
;
Languages

  
!insertmacro MUI_LANGUAGE "English"

Function .onInit
    
${GetParameters} $0
    ClearErrors
    
${GetOptions} `$0'/silent-install' $;Nếu không get được thì có Errorsử dụng error đó bằng IfErrors 0 LamGiDo
    IfErrors 0 SilentInstall_TRUE
        StrCpy $Var_Silent 0
        
Goto SilentInstall_FALSE
    SilentInstall_TRUE
:
        
StrCpy $Var_Silent 1
    SilentInstall_FALSE
:
    ;
    ${
GetParameters} $0
    ClearErrors
    
${GetOptions} `$0'/location=' $1
    StrLen 
$'$1'
    
${If} $3
        StrCpy $INSTDIR 
'$1'
    
${Else}
        
StrCpy $INSTDIR 'C:\Test\Location'
    
${EndIf}
    ;
    ;If 
user run setup in silent modeI want to run the Installer as Child Elevated process with parameters of silentthe Main non-Elevated process will auto quit
    
${If} $Var_Silent == 1
        
${If} ${AtLeastWinVista}
            
UserInfor::GetAccountType
            Pop 
$0
            
${If} $!= 'admin'
                
CopyFiles '$EXEPATH' '$TEMP'
                
ExecShell 'runas' '$TEMP/TEST-DualMode.exe /silent-install /location=$INSTDIR'
                
Quit
            
${EndIf}
        ${EndIf}
    ${EndIf}
FunctionEnd

;--------------------------------
;
Installer Sections

Section 
"Dummy Section" SecDummy
  SetOutPath 
"$INSTDIR"
  
WriteRegStr HKCU "Software\Dual Mode Installer" "" $INSTDIR
  WriteUninstaller 
"$INSTDIR\Uninstall.exe"
SectionEnd

;--------------------------------
;
Descriptions

  
;Language strings
  LangString DESC_SecDummy 
${LANG_ENGLISH"A test section."

  
;Assign language strings to sections
  
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
    
!insertmacro MUI_DESCRIPTION_TEXT ${SecDummy} $(DESC_SecDummy)
  !
insertmacro MUI_FUNCTION_DESCRIPTION_END

;--------------------------------
;
Uninstaller Section

Section 
"Uninstall"
  
Delete "$INSTDIR\Uninstall.exe"
  
RMDir "$INSTDIR"
  
DeleteRegKey /ifempty HKCU "Software\Dual Mode Installer"
SectionEnd 
Thanks for help.
meoit is offline   Reply With Quote
Old 5th March 2020, 17:28   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,280
ExecShell command syntax is wrong and you used incorrect path slash.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 6th March 2020, 00:24   #3
meoit
Member
 
Join Date: Oct 2014
Location: $DESKTOP
Posts: 99
Thanks Anders !

I edited code, but also un-success.

PHP Code:
Unicode true
RequestExecutionLevel user

!include 'MUI2.nsh'
!include 'FileFunc.nsh'
!include 'x64.nsh'
!include 'WinVer.nsh'

Var /GLOBAL Var_Silent
!define My_Temp_EXEC '$TEMP\TMP.exe'
;--------------------------------
;
General

  
;Name and file
  Name 
"Non-Elevated/Elevated Dual Mode Installer"
  
OutFile "Tv.exe"

  
;Default installation folder
  InstallDir 
"$LOCALAPPDATA\Modern UI Test"

  
;Get installation folder from registry if available
  InstallDirRegKey HKCU 
"Software\Dual Mode Installer" ""

;--------------------------------
;Interface 
Settings

  
!define MUI_ABORTWARNING

;--------------------------------
;
Pages

  
!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\License.txt"
  
!insertmacro MUI_PAGE_COMPONENTS
  
!insertmacro MUI_PAGE_DIRECTORY
  
!insertmacro MUI_PAGE_INSTFILES

  
!insertmacro MUI_UNPAGE_CONFIRM
  
!insertmacro MUI_UNPAGE_INSTFILES

;--------------------------------
;
Languages

  
!insertmacro MUI_LANGUAGE "English"


!define RunAsAdminQuitSI '!insertmacro RunAsAdminQuitSI'
!macro RunAsAdminQuitSI
    
${If} ${AtLeastWinVista}
        
UserInfor::GetAccountType
        Pop 
$0
        
${If} $!= 'admin'
            
CopyFiles '$EXEPATH' '${My_Temp_EXEC}'
            
ExecShell 'runas' '$\"${My_Temp_EXEC} $\" -silent-install -location=$INSTDIR'
            
Quit
        
${EndIf}
    ${EndIf}
!
macroend

Function .onInit
    
${GetParameters} $0
    ClearErrors
    
${GetOptions} `$0'-silent-install' $1
    
${IfNot} ${Errors}
        
StrCpy $Var_Silent 1
    
${Else}
        
StrCpy $Var_Silent 0
    
${EndIf}
    ;
    ${
GetParameters} $0
    ClearErrors
    
${GetOptions} `$0'-location=' $1
    StrLen 
$'$1'
    
${If} $3
        StrCpy $INSTDIR 
'$1'
    
${Else}
        
StrCpy $INSTDIR 'C:\Test\Location'
    
${EndIf}
    ;
    ;If 
user run setup in silent modeI want to run the Installer as Child Elevated process with parameters of silentthe Main non-Elevated process will auto quit
    
${If} $Var_Silent == 1
        
${RunAsAdminQuitSI}
    ${EndIf}
FunctionEnd

;--------------------------------
;
Installer Sections

Section 
"Dummy Section" SecDummy
  SetOutPath 
"$INSTDIR"
  
WriteRegStr HKCU "Software\Dual Mode Installer" "" $INSTDIR
  WriteUninstaller 
"$INSTDIR\Uninstall.exe"
SectionEnd

;--------------------------------
;
Descriptions

  
;Language strings
  LangString DESC_SecDummy 
${LANG_ENGLISH"A test section."

  
;Assign language strings to sections
  
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
    
!insertmacro MUI_DESCRIPTION_TEXT ${SecDummy} $(DESC_SecDummy)
  !
insertmacro MUI_FUNCTION_DESCRIPTION_END

;--------------------------------
;
Uninstaller Section

Section 
"Uninstall"
  
Delete "$INSTDIR\Uninstall.exe"
  
RMDir "$INSTDIR"
  
DeleteRegKey /ifempty HKCU "Software\Dual Mode Installer"
SectionEnd 
meoit is offline   Reply With Quote
Old 6th March 2020, 01:30   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,280
It is still wrong, please try reading the documentation to understand the syntax.

Quote:
ExecShell 'open' 'cmd.exe' '/K echo hello'

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 12th March 2020, 13:23   #5
meoit
Member
 
Join Date: Oct 2014
Location: $DESKTOP
Posts: 99
I fixed it. Thanks.
meoit 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