【问题标题】:WinRar -sp<> flag not working with self-extractorsWinRar -sp<> 标志不适用于自解压器
【发布时间】:2014-06-20 11:25:31
【问题描述】:

我使用 Winrar 3 创建自提取器,并使用-sp 标志将参数传递给捆绑在其中的可执行文件。它工作正常。 在我将 WinRar 更新为 5.1 后,它停止工作。 -sp&lt;&gt; 标志不再为我工作。

还有其他人面临类似的问题吗? 是否有任何其他标志可以用来将参数传递给自提取器调用的可执行文件。 我阅读了有关可用标志的以下文档。 http://www.winrar-tr.com/winrar/Help/ENG/html/HELPGUISFXCmd.htm

【问题讨论】:

    标签: winrar self-extracting sfx


    【解决方案1】:

    可执行文件的参数可以直接在注释文件中指定SFX模块的参数。

    这是一个演示此技术的示例批处理文件:

    @echo off
    cd /D "%TEMP%"
    
    rem Create the file for the SFX module with the SFX options.
    
    echo ;The comment below contains SFX script commands.>TestSetup.txt
    echo.>>TestSetup.txt
    echo Setup=Test.bat Switch "One more parameter">>TestSetup.txt
    echo Overwrite=1>>TestSetup.txt
    echo Title=Test Installation>>TestSetup.txt
    echo Text>>TestSetup.txt
    echo {>>TestSetup.txt
    echo ^<font face='Arial'^>An SFX test which just shows how SFX module runs the installer.^<br^>^<br^>Just click on button Install or hit RETURN.^</font^>>>TestSetup.txt
    echo }>>TestSetup.txt
    
    rem Create the batch file executed by SFX archive.
    
    echo @echo %%0 %%*>Test.bat
    echo @pause>>Test.bat
    echo @del %%0 ^>nul>>Test.bat
    
    rem Create the SFX archive.
    
    RAR.exe a -sfx -c -zTestSetup.txt TestSetup.exe Test.bat
    
    rem Delete the created batch and comment file.
    
    del Test.bat
    del TestSetup.txt
    
    rem Run the self-extracting archive. User has to press only RETURN.
    
    start /wait TestSetup.exe
    
    rem Delete the self-extracting archive.
    
    :DeleteLoop
    del TestSetup.exe >nul
    if exist TestSetup.exe goto DeleteLoop
    

    此批处理文件首先在临时文件目录中创建文本文件 TestSetup.txt,其内容为:

    ;The comment below contains SFX script commands.
    
    Setup=Test.bat Switch "One more parameter"
    Overwrite=
    Title=Test Installation
    Text
    {
    <font face='Arial'>An SFX test which just shows how SFX module runs the installer.<br><br>Just click on button Install or hit RETURN.</font>
    }
    

    对您来说重要的是以Setup= 开头的行。

    • Test.bat 是解压后要执行的文件。
    • Switch 是作为第一个参数传递给Test.bat 的选项。
    • "One more parameter" 是第二个参数,其中包含空格以传递给 Test.bat,因为有空格,所以必须用双引号括起来。

    接下来批处理文件继续创建 Test.bat 内容:

    @echo %0 %*
    @pause
    @del %0 >nul
    

    这个小批处理文件只是在第一行输出它是如何被 SFX 存档调用的,接下来等待用户击键并最后删除自己。因此,将批处理文件提取到哪个目录并不重要。默认为当前目录,即临时文件所在的目录。

    然后批处理文件创建 SFX 存档 TestSetup.exe。所用开关的详细信息请参见WinRAR的程序文件目录中的Rar.txt

    请注意,Rar.exe 行只有在 WinRAR 的程序文件目录包含在环境变量 PATH 中或 Windows 找不到 @ 时才有效987654332@ 是 WinRAR 的控制台版本。将完整路径的行修改为双引号中的 Rar.exe,以使批处理文件的这一行独立于 PATH 中包含的目录。

    自解压 RAR 存档创建后,文件 Test.batTestSetup.txt 将被删除,不再需要。

    现在创建的 SFX 存档 TestSetup.exe 被调用,在按 RETURN 键后,您会看到 Test.bat 是使用 Test.bat 中指定的 2 个参数调用的strong>TestSetup.txt。

    批处理文件最后也删除创建的 SFX 存档。

    【讨论】:

    • 感谢 Mofi 的详细描述。我尝试了同样的事情,但它对我不起作用。我与 WinRar 的一位工程师交谈,他同意如果 exe 名称包含在双引号中,则 WinRar 中存在错误。例如 Setup=Test.bat 工作但 Setup="Test.bat" 不工作。
    • 谢谢!回答了我的(类似)问题
    • 创建自动 SFX 存档,您可能会考虑使用 -cfg- 开关以避免 WinRAR 的默认设置依赖性。否则,WinRAR 默认设置可能会覆盖您的 -zOptions.txt 文件内容。在stackoverflow.com/a/24598044/378115,您可以找到另一个使用开关的 Mofi 示例。谢谢莫菲
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-02
    相关资源
    最近更新 更多