I'm running the script shown below and neither the directory nor the logical link are being created. I'm not sure what I'm doing wrong. Each call returns a code of 0 (zero). I'm using the information available here
Execute Command-Line Command from NSIS
https://nsis.sourceforge.io/Docs/Chapter4.html
RequestExecutionLevel admin
# includes
!include .\PrependEnv.nsh
# definitions
Outfile "007-exec-examples.exe"
InstallDir "C:\temp\nsis-examples\007-exe-examples"
Page Directory
Page InstFiles
# section to copy files and manipulate env variable
Section
# copy files
DetailPrint ""
DetailPrint "Copying files to $InstDir..."
DetailPrint ""
SetOutPath "$InstDir\resources"
File /a /r "resources\"
# create a dir
DetailPrint ""
DetailPrint "Making dir $InstDir"
Exec 'mkdir $InstDir\delete_me'
Pop $0
DetailPrint "RegPrependString:Error=$0 (Should be 0)"
# create a logical link
DetailPrint ""
DetailPrint "Creating logical link as C:\_YES to $InstDir\delete_me."
Exec 'mklink /D $InstDir\_MY_LINK $InstDir\delete_me'
Pop $0
DetailPrint "RegPrependString:Error=$0 (Should be 0)"
SectionEnd
--- EDIT ----------------------------
This also fails but does give a indication that an error occurred.
# ---
#
# This script tries to create a dir and a logical link.
#
# ---
RequestExecutionLevel admin
# includes
!include .\PrependEnv.nsh
# definitions
Outfile "008-exec-examples.exe"
InstallDir "C:\temp\nsis-examples\008-exe-examples"
ShowInstDetails show
Page Directory
Page InstFiles
# section to copy files and manipulate env variable
Section
# copy files
DetailPrint ""
DetailPrint "Copying files to $InstDir..."
DetailPrint ""
SetOutPath "$InstDir\resources"
File /a /r "resources\"
# create a dir
DetailPrint ""
DetailPrint "Making dir $InstDir\delete_me"
nsExec::ExecToStack 'mkdir $InstDir\delete_me'
Pop $0
Pop $1
DetailPrint "RegPrependString:Error=$0 (Should be 0)"
DetailPrint "$1"
# create a logical link
DetailPrint ""
DetailPrint "Creating logical link as $InstDir\_MY_LINK to $InstDir\delete_me."
nsExec::ExecToStack 'mklink /D $InstDir\_MY_LINK $InstDir\delete_me'
Pop $0
Pop $1
DetailPrint "RegPrependString:Error=$0 (Should be 0)"
DetailPrint "$1"
SectionEnd
--- EDIT --------------------------------
Here's a full working example based on the accepted answer. This example creates a directory, a shortcut, and a link.
# ---
#
# This script tries to create a dir and a logical link.
#
# ---
RequestExecutionLevel admin
# includes
!include .\PrependEnv.nsh
# definitions
Outfile "009-exec-examples.exe"
InstallDir "C:\temp\nsis-examples\009-exe-examples"
ShowInstDetails show
Page Directory
Page InstFiles
# section to copy files and manipulate env variable
Section
# copy files
DetailPrint ""
DetailPrint "Copying files to $InstDir..."
DetailPrint ""
SetOutPath "$InstDir\resources"
File /a /r "resources\"
# create a dir
DetailPrint ""
DetailPrint "Making dir $InstDir\delete_me"
CreateDirectory $InstDir\delete_me
Pop $0
Pop $1
DetailPrint "RegPrependString:Error=$0 (Should be 0)"
DetailPrint "$1"
# create a short cut
DetailPrint ""
DetailPrint "Creating SHORTCUT as $InstDir\_MY_SHORTCUT to $InstDir\delete_me."
CreateShortCut $InstDir\_MY_SHORTCUT.lnk $InstDir\delete_me
Pop $0
Pop $1
DetailPrint "RegPrependString:Error=$0 (Should be 0)"
DetailPrint "$1"
# create a logical link
DetailPrint ""
DetailPrint "Creating LINK as $InstDir\_MY_SHORTCUT to $InstDir\delete_me."
nsExec::ExecToStack 'cmd.exe /C mklink /D $InstDir\_MY_LINK $InstDir\delete_me'
Pop $0
Pop $1
DetailPrint "RegPrependString:Error=$0 (Should be 0)"
DetailPrint "$1"
SectionEnd