Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6345
  • Last Modified:

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

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
Deathader
Asked:
Deathader
  • 5
  • 4
1 Solution
 
DeathaderAuthor Commented:
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
 
avdejCommented:
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
 
DeathaderAuthor Commented:
Is it possible to do what i'm looking for with another archiver, maybe 7zip?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
DeathaderAuthor Commented:
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
 
avdejCommented:
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
 
DeathaderAuthor Commented:
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
 
avdejCommented:
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
 
DeathaderAuthor Commented:
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
 
ansa45Commented:
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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now