Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
534 views
in Technique[技术] by (71.8m points)

winrar - How to create self-extracting RAR archive not showing anything on execution?

I am trying to create a self-extracting archive that extracts to "%USERPROFILE%Desktop" with WinRar. However, when I run it, it extracts to the SFX's current directory, not my desktop. Does the path to extract option work at all?

I'm using the 32-bit command line module.

I also checked the 'hide all' box for silent mode which appears to do absolutely nothing and the command prompt window still appears with showing information on what is extracted.

I want that SFX archive extracts the .exe and the folder contained in the SFX file to the desktop without any messages popping up.

Any suggestions?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It is possible to create an SFX RAR archive extracting all files and folders directly to
"%USERPROFILE%Desktop" without showing a window.

This can be done with WinRAR after selecting the files and folders and clicking on icon Add in the toolbar by

  1. checking on tab General the option Create SFX archive,
  2. clicking on tab Advanced on button SFX options,
  3. entering on SFX tab General for Path to extract the string "%USERPROFILE%Desktop" which results in automatic selection of option Absolute path which is right,
  4. selecting on SFX tab Modes the option Hide all,
  5. selecting on SFX tab Module the SFX module Default.sfx (WinRAR GUI SFX module),
  6. closing Advanced SFX options window with button OK,
  7. entering on tab General the name for the SFX archive,
  8. and starting compression with button OK.

A command prompt window will be always displayed if module WinCon.sfx is used for the SFX archive as in this case Windows detects automatically on start of the SFX archive that this is a console application and opens a command prompt window in which the console SFX is executed.

Creating such an SFX archive can be done also with a batch file:

@echo off
echo ;The comment below contains SFX script commands>"%TEMP%SfxOptions.txt"
echo/>>"%TEMP%SfxOptions.txt"
echo Path="%%USERPROFILE%%Desktop">>"%TEMP%SfxOptions.txt"
echo Silent=^1>>"%TEMP%SfxOptions.txt"
"%ProgramFiles%WinRARRar.exe" a -c -cfg- -ep1 -idq -m5 -mdg -r -s -sfx -y "-z%TEMP%SfxOptions.txt" "PathName of your SFX.exe" "PathFolder to add" "PathFile to add"
if errorlevel 1 goto Failure
del "%TEMP%SfxOptions.txt"
goto :EOF

:Failure
del "%TEMP%SfxOptions.txt"
echo/
echo Error on creation of "PathName of your SFX.exe"
echo/
pause

In this batch file must be modified for usage:

  1. Path to program files folder of WinRAR containing console version Rar.exe and also the SFX module Default.sfx.
  2. Path and name of the SFX archive to create.
  3. Path and name of folder and/or file to add to the archive.

The used switches are explained in text file Rar.txt in program files folder of WinRAR.

One more note on switch -ep1:

Everything up to last backslash in name of folder and/or file to add to archive is removed from name on adding the folder or file to the archive.

On adding a folder to a RAR archive it makes a difference if the folder is specified with or without a backslash at end.

Example:

A directory tree like

  • C:Temp
    • MyFolder
      • Subfolder 1
      • Subfolder 2
        • File X
      • File Y

is compressed with

Rar.exe a -ep1 -r C:TempDemo1.rar C:TempMyFolder

with following files and folders in archive C:TempDemo1.rar

  • MyFolder
    • Subfolder 1
    • Subfolder 2
      • File X
    • File Y

while using

Rar.exe a -ep1 -r C:TempDemo2.rar C:TempMyFolder

or using

Rar.exe a -ep1 -r C:TempDemo2.rar C:TempMyFolder*

results in following files and folders in archive C:TempDemo2.rar

  • Subfolder 1
  • Subfolder 2
    • File X
  • File Y

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...