このバッチ コードは、パスワードで保護されたSFX ( S el F -e X tracting )を作成する方法を示しています。もちろん、それらを追加する場合は、カスタム アイコンも使用します。
@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
他のスイッチとコマンドについては、このバッチを実行して Winrar のヘルプ ファイルを開くことができます。
@echo off
Set WinrarHelp=%ProgramFiles%\WinRAR\WinRAR.chm
Start "" "%WinrarHelp%"