简体   繁体   中英

WinRar SFX, extract to dynamic folder

I have RAR SFX with some programs. Depending on some conditions (command line parameter is something i can do), SFX should either extract to TEMP folder, or the current folder.

It's basicaly new version of the software. If downloaded from the web, extraction should go into temp folder, and then installation searches for the map where SW is located. If downloaded from inside the program, then i know the program location relative to download path and extraction should go into current folder...

Any way I can achieve this using RAR SFX?

TNX.

Inside your program you can skip SFX header of file and extract it as regular RAR file in folder yo want. It need few lints of code or embding Winrar or 7zip liraries.

This batch code show you how we can create an SFX ( S el F -e X tracting) protected with a password and with a custom icon too if you want to add them of course

@echo off
Set SFX_Name=TestSFX.exe
Set SfxOptions=SfxOptions.txt
Set AddFile=MyBatchFile.bat
Set Icon=HackooIcon.ico
Set Winrar="%ProgramFiles%\WinRAR\WinRar.exe"
Set ExtractedPath=%tmp%\hackoo
Set Setup=%ExtractedPath%\MyBatchFile.bat
Set Password=hackoo123

(
    echo ;The comment below contains SFX script commands
    echo Path="%ExtractedPath%"
    echo Silent=1
    echo OverWrite=1
    echo Setup="%Setup%"
)> "%SfxOptions%"

%Winrar% a -c -cfg- -ep1 -idq -m5 -mdg -r -s -sfx -y -iicon"%Icon%" -hp"%Password%" "-z%SfxOptions%" "%SFX_Name%" "%AddFile%"
if errorlevel 1 goto Failure
::del "%~dp0SfxOptions.txt"
goto :EOF

:Failure
::del "%~dp0SfxOptions.txt"
echo.
echo Error on creation of "%~dp0%SFX_Name%"
echo.
pause

For others switchs and commands you can execute this batch to open the help file of Winrar :

@echo off
Set WinrarHelp=%ProgramFiles%\WinRAR\WinRAR.chm
Start "" "%WinrarHelp%"

rar命令行中的“ -c”开关是什么意思?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM