Solved

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

Posted on 2009-04-03
10
5,383 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
ID: 24062131
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
ID: 24062267
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
ID: 24062346
Is it possible to do what i'm looking for with another archiver, maybe 7zip?
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 3

Expert Comment

by:avdej
ID: 24062889
0
 

Author Comment

by:Deathader
ID: 24063072
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
 
LVL 3

Expert Comment

by:avdej
ID: 24063786
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
ID: 24064201
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
ID: 24064333
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
ID: 24064483
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
ID: 25103122
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

786 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