Solved

How do I make a SFX archive with winrar via CMD?

Posted on 2009-04-03
10
5,238 Views
Last Modified: 2013-12-01
I'm trying to make a SFX archive in winrar via the command line. I read the winrar manual, but I am completely lost.

I want to create a SFX that:
-Extracts the contents to: C:\WINDOWS\System32
-Advanced>SFX Options>Modes>Silent Mode>Hide All
-Overwrites the files

I don't care about the other settings.

Thanks,
Alex
0
Comment
Question by:Deathader
  • 5
  • 4
10 Comments
 

Author Comment

by:Deathader
Comment Utility
I have tried putting the following code in a batch file. It makes the files, but you can see the dialog and it doesn't run anything on completion. If anyone can help that would be great.
"C:\Program Files\WinRAR\RAR.exe"  a -sfx  -d"C:\WINDOWS\System32" -s1 -esh -idq -inul -o+ -m5 -mt2 -r -s -t  "output.exe"  @"files_to_include.txt"

pause

Open in new window

0
 
LVL 3

Expert Comment

by:avdej
Comment Utility
Hi, Alex!

Basicaly, for your particular need, you have to execute the following line:
rar a -o+ -rr -t -ep -sfx <SFX_name> @<filelist>

where
<SFX_name> should be replaced with the target archive name (without .exe extention)
AND
<filelist> should be replaced with a path of a text file with files to add (one per line)
OR
@<filelist> should be replaced with a space separated files listed directly here (i.e. without using an outer text file).

But to ensure that it will really work I suggest you do the following:
*. Copy the attached code snippet into a .cmd file
*. Place the file into directory your SFX archive should be created in.
*. Change the entries in first THREE lines after =...
    with
   1) full path of WinRar directory (not WinRar.exe!)
   2) name of the target SFX archive (without .exe)
   3) full path of a text file with full paths of files to archive
*. Execute the .cmd file from that directory
*. Your SFX file will be created here as well.
*. Here you are!


Example content for filelist.exe:
C:\Temp\file1
C:\Temp\DirA\file2
C:\Temp\DirB\file3
...

NOTE: Unfortunately it seems to be not possible to set the advanced SFX options you mentioned above in the command line version of the WinRar utility. Thus your user will still have to manually navigate to C:\WINDOWS\system32 and to manually confirm any file overwriting.



set winrar=C:\Program Files\WinRAR

set sfx=MyArchive

set files=C:\Temp\filelist.txt
 

set winrar="%winrar%\rar"
 

%winrar% a -o+ -rr -t -ep -sfx %sfx% @%files%
 

pause

Open in new window

0
 

Author Comment

by:Deathader
Comment Utility
Is it possible to do what i'm looking for with another archiver, maybe 7zip?
0
 
LVL 3

Expert Comment

by:avdej
Comment Utility
0
 

Author Comment

by:Deathader
Comment Utility
I've known about iexpress. I was using it originally, but I write 50 - 60 SFX installers / day, and it was taking forever to make them. So I wrote a vb.net program that you plug the file names into and it writes a batch file. If there is a way to run iexpress via command line, that would be great :)
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 3

Expert Comment

by:avdej
Comment Utility
Yes, there is. But you will have to
1. create/have a .SED file (a kind of .INF file for IExpress) for the target archive. Run an initial single pass with IExpress GUI to include all the files into it and to set the desired (quiet) options . [Of course, once you know/see the proper format for the manually created .SED file, you can generate such a file from BATCH or VB too. Open it in text editor and look what's inside].

2. THEN run IExpress with the following options:
iexpress /N /Q archive.SED

where archive.SED is the .SED file you want to provide.

The target archive will be created according to 'TargetName=' value set within .SED file.

A CS proverb says: Programmable is anything what is computable.

As you can see, your particular task is computable, so it IS programmable.

I wish you a lot of success!
Best regards,
Avdej



0
 

Author Comment

by:Deathader
Comment Utility
I tried your /n /q command and it didn't work. I removed the /q switch, and ran it, and got this error:

Error Opening IExpress Self Extraction Directive File.

0
 
LVL 3

Accepted Solution

by:
avdej earned 250 total points
Comment Utility
It works rather perfectly.
Look at the Error message!

> Error Opening IExpress Self Extraction Directive File

'S'elf 'E'xtraction 'D'irective File IS the the .SED file I've mentioned above. Did you provided IT as the third argument? Please read my previous comment/instructions carefully.
0
 

Author Comment

by:Deathader
Comment Utility
Fixed it :) I forgot to CD to the dir with the .SED file in it. I tried doing

iexpress /N /Q C:\Documents and Settings\Alex\Desktop\project1.SED

and

iexpress /N /Q "C:\Documents and Settings\Alex\Desktop\project1.SED"

but neither worked. When I cd' to the directory that the SED file was in, it worked perfectly :D

Thank you very much :)

0
 

Expert Comment

by:ansa45
Comment Utility
Using rar this way and use the -s1 and -o+ BEFORE or AFTER the -sfx command doesn't really help in suppressing the dialog box or overwriting files.  If you just execute the output.exe from a command line, the silent and overwrite parameters don't kick in and you're still presented with dialog boxes.  Of course though, if you double click the output.exe in Windows explorer, you'll see nothing (just output.exe in your task manager).  So my question would be:  executing output.exe from a cmd line - how do you get it to extract silently and overwrite if files are already there (where you're extracting to).


<path to rar>\RAR.exe"  a -sfx  -d"C:\WINDOWS\System32" -s1 -esh -idq -inul -o+ -m5 -mt2 -r -s -t  "output.exe"  @"files_to_include.txt"
pause
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This is an explanation of a simple data model to help parse a JSON feed
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now