Old 3rd April 2020, 16:16   #1
ikreb
Junior Member
 
Join Date: Aug 2018
Posts: 14
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.

code:

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.
ikreb is offline   Reply With Quote
Old 3rd April 2020, 22:03   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,288
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.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 4th April 2020, 09:38   #3
ikreb
Junior Member
 
Join Date: Aug 2018
Posts: 14
Thank you for your answer. The strange is that I tried:

code:

IfFileExists $TEMP\Test-Installer\FortiClientVPNSetup_$Platform.exe 0 +2
MessageBox MB_OK "Exists."



And it shows me the MessageBox. But If I test

code:

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



It jumps. However I tried this:

code:

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 is offline   Reply With Quote
Old 4th April 2020, 10:46   #4
ikreb
Junior Member
 
Join Date: Aug 2018
Posts: 14
Thanks for your answer. It doesn't still work.

I tried:
code:

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:
code:

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?
ikreb is offline   Reply With Quote
Old 5th April 2020, 00:22   #5
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,288
It is hard to say what the exact problem is.

Works fine for me

PHP Code:
!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.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 5th April 2020, 22:45   #6
ikreb
Junior Member
 
Join Date: Aug 2018
Posts: 14
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.
ikreb is offline   Reply With Quote
Old 5th April 2020, 23:23   #7
ikreb
Junior Member
 
Join Date: Aug 2018
Posts: 14
Thank you for your efforts. I solved it. The file was probably corrupt.
ikreb is offline   Reply With Quote
Old 6th April 2020, 02:04   #8
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,288
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.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 7th April 2020, 08:02   #9
ikreb
Junior Member
 
Join Date: Aug 2018
Posts: 14
Thanks, I will fix this.
ikreb 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