如何让NSIS从临时目录安装和执行文件?

时间:2011-02-25 16:04:53

标签: nsis

我正在使用以下NSIS脚本:

Name "My app wrapper"
Outfile "MyAppSetup.exe"
InstallDir $TEMP\MyApp\Install
Function .onInit
SetSilent silent
FunctionEnd
Section ""
    SetOutPath $TEMP\MyApp\Install
    File installer.msi
    File setup.exe
    Exec setup.exe
SectionEnd

目的是安装程序将这两个文件:installer.msi和setup.exe(它是一个安装prereq的引导程序然后调用installer.msi)包装到MyApp Setup.exe文件中。运行MyAppSetup.exe时,它应该将installer.msi和setup.exe解压缩到$ Temp \ MyApp \ Install目录,它应该从该目录运行setup.exe。

但是,当我从桌面运行MyAppSetup时,它会执行它在桌面上找到的setup.exe文件,我甚至看不到C:\ Temp中的MyApp \ Install目录。

我需要做些什么才能让这个脚本将文件安装到正确的位置并执行正确的文件?

3 个答案:

答案 0 :(得分:12)

Section
InitPluginsDir
SetOutPath "$pluginsdir\MyApp\Install" ;It is better to put stuff in $pluginsdir, $temp is shared

File installer.msi
File setup.exe

ExecWait '"$pluginsdir\MyApp\Install\setup.exe"' ;You should always use full paths and proper quotes

SetOutPath $exedir ;Change current dir so $temp and $pluginsdir is not locked by our open handle
SectionEnd

答案 1 :(得分:2)

我不知道它是否会解决你的问题,但我会写:

Exec $TEMP\MyApp\Instal\setup.exe

你确定$ TEMP指向C:/ Temp吗?你看过了吗?

答案 2 :(得分:0)

这是另一种方法

Function .onInit

    InitPluginsDir
        File /oname=$PLUGINSDIR\test.exe "test.exe"

FunctionEnd

Section "Exec file" SecFile

    nsExec::Exec $PLUGINSDIR\test.exe

SectionEnd