Skip to content
⌘ NSIS Forum Archive

Can't execute a executable with exec

9 posts

ikreb#

Can't execute a executable with exec

Hello,

I try to execute a exe. I tried: nsExec::ExecToStack, nsExec::Exec, ExecWait, ExecShell. But I get each time as return value "error". So I don't know actually what the error could be.

But if I run the exe with cmd it works.


SetCompress auto
SetCompressor lzma
CRCCheck on
ManifestDPIAware true

;======================================================
; General

Unicode true
ManifestSupportedOS all

; Name and file
Name "Installer"

OutFile "Fortinet_Installer.exe"

; Request application privileges for Windows
RequestExecutionLevel admin

;======================================================
; Imports

!include LogicLib.nsh
!include WinVer.nsh
!include WordFunc.nsh
!include x64.nsh

;======================================================
; Variables

Var Platform

;======================================================
; Functions

Function .onInit
InitPluginsDir

; CWD setzen
SetOutPath "$TEMP\Test-Installer"

${If} ${IsNativeAMD64}
StrCpy $Platform "x64"
File FortiClientVPNSetup_x64.exe
${ElseIf} ${IsNativeIA32}
StrCpy $Platform "x86"
File FortiClientVPNSetup_x86.exe
${ElseIf} ${IsNativeARM64}
; Install ARM64 64-bit driver/library
Abort "Unsupported CPU architecture!"
${Else}
Abort "Unsupported CPU architecture!"
${EndIf}

DetailPrint 'CPU architecture "$Platform" recognized.'
FunctionEnd


;======================================================
; Sections

Section

DetailPrint '"Run $TEMP\FortiClientVPNSetup_$Platform.exe /quiet /norestart"'
nsExec::ExecToStack '"$TEMP\FortiClientVPNSetup_$Platform.exe" /quiet /norestart'
Pop $0
Pop $1
DetailPrint '"$0"'
DetailPrint '"$1"'

SectionEnd

You could get the executable from here.
Anders#
You extract to "$TEMP\Test-Installer\F...exe" but try to execute "$TEMP\F...exe".

You don't need nsExec for this, you can use ExecWait.
ikreb#
Thank you for your answer. The strange is that I tried:


IfFileExists $TEMP\Test-Installer\FortiClientVPNSetup_$Platform.exe 0 +2
MessageBox MB_OK "Exists."
And it shows me the MessageBox. But If I test


IfFileExists $TEMP\FortiClientVPNSetup_$Platform.exe 0 +2
MessageBox MB_OK "Does not exist."
It jumps. However I tried this:


DetailPrint '"Run $TEMP\Test-Installer\FortiClientVPNSetup_$Platform.exe /quiet /norestart"'
ExecWait '"$TEMP\Test-Installer\FortiClientVPNSetup_$Platform.exe" /quiet /norestart' $0
DetailPrint "$0"

DetailPrint '"Run $TEMP\Test-Installer\FortiClientVPNSetup_$Platform.exe /quiet /norestart"'
nsExec::ExecToStack '"$TEMP\Test-Installer\FortiClientVPNSetup_$Platform.exe" /quiet /norestart'
Pop $0
Pop $1
DetailPrint '"$0", "$1"'
This is the result.

1. DetailPrint -> empty
2. DetailPrint "error", ""

So sadly it still doesn't work.
ikreb#
Thanks for your answer. It doesn't still work.

I tried:

IfFileExists $TEMP\FortiClientVPNSetup_$Platform.exe 0 +2
MessageBox MB_OK "Does not exist."

IfFileExists $TEMP\Test-Installer\FortiClientVPNSetup_$Platform.exe 0 +2
MessageBox MB_OK "Exists."
And it show the MessageBox with "Exists". So something couldn't be right. Aslo if I run:

DetailPrint '"Run $TEMP\Test-Installer\FortiClientVPNSetup_$Platform.exe /quiet /norestart"'
ExecWait '"$TEMP\Test-Installer\FortiClientVPNSetup_$Platform.exe" /quiet /norestart' $0
DetailPrint "$0"

DetailPrint '"Run $TEMP\Test-Installer\FortiClientVPNSetup_$Platform.exe /quiet /norestart"'
nsExec::ExecToStack '"$TEMP\Test-Installer\FortiClientVPNSetup_$Platform.exe" /quiet /norestart'
Pop $0
Pop $1
DetailPrint '"$0", "$1"'
This are the result:

1. DetailPrint: empty
2. DetailPrint: "error", ""

Do you have still any idea what my stupid mistake could be?
Anders#
It is hard to say what the exact problem is.

Works fine for me

!include x64.nsh
Var Platform
Section
InitPluginsDir
SetOutPath $PluginsDir
${If} ${IsNativeAMD64}
    StrCpy $Platform "x64"
    File "/oname=$PluginsDir\MyApp_x64.exe" "${NSISDIR}\Bin\MakeLangId.exe" ; Fake example app
${ElseIf} ${IsNativeIA32}    
${OrIf} ${IsWow64}
    StrCpy $Platform "x86"
    File "/oname=$PluginsDir\MyApp_x86.exe" "${NSISDIR}\Bin\MakeLangId.exe" ; Fake example app
${Else}
    Abort "Unsupported CPU architecture!"
${EndIf}
ExecWait '"$PluginsDir\MyApp_$Platform.exe" /foo /bar' $0
DetailPrint 'ExitCode=$0'
SetOutPath $Temp # Release lock on $PluginsDir directory so it can be deleted
SectionEnd 
You could try Process Monitor, it will tell you if it finds the path. It might also provide some clues as to why the process fails to start if it actually finds the file.
ikreb#
I tried it with other executable files. And everything is fine. So what could be the difference to other exe files? Do you have any idea? Or is it a bug at nsis?

I went to the temp directory. If I start another exe-file manual it works. But if I start the error exe file I get this error message:

The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail.

I will try to reearch further but maybe you have still an idea.
Anders#
You should not place executable files in $temp anyway because there might be other 3rd-party .DLLs in there creating a conflict. $pluginsdir is your private $temp.