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

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?

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
checking on tab General the option Create SFX archive,
clicking on tab Advanced on button SFX options,
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,
selecting on SFX tab Modes the option Hide all,
selecting on SFX tab Module the SFX module Default.sfx (WinRAR GUI SFX module),
closing Advanced SFX options window with button OK,
entering on tab General the name for the SFX archive,
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%\WinRAR\Rar.exe" a -c -cfg- -ep1 -idq -m5 -mdg -r -s -sfx -y "-z%TEMP%\SfxOptions.txt" "Path\Name of your SFX.exe" "Path\Folder to add" "Path\File to add"
if errorlevel 1 goto Failure
del "%TEMP%\SfxOptions.txt"
goto :EOF
:Failure
del "%TEMP%\SfxOptions.txt"
echo/
echo Error on creation of "Path\Name of your SFX.exe"
echo/
pause
In this batch file must be modified for usage:
Path to program files folder of WinRAR containing console version Rar.exe and also the SFX module Default.sfx.
Path and name of the SFX archive to create.
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:\Temp\Demo1.rar C:\Temp\MyFolder
with following files and folders in archive C:\Temp\Demo1.rar
MyFolder
Subfolder 1
Subfolder 2
File X
File Y
while using
Rar.exe a -ep1 -r C:\Temp\Demo2.rar C:\Temp\MyFolder\
or using
Rar.exe a -ep1 -r C:\Temp\Demo2.rar C:\Temp\MyFolder\*
results in following files and folders in archive C:\Temp\Demo2.rar
Subfolder 1
Subfolder 2
File X
File Y

Related

How to unzip several *.zip archive files into separate folders?

I searched with Google but I didn't find something for Windows.
How can I extract several files into several folders?
For example: a.zip, b.zip and c.zip into the folders a, b and c.
I am looking for a command prompt command or a batch file solution.
Thanks
With using WinRAR in GUI mode:
Start WinRAR.
Select all the *.zip files.
Click on icon Extract To in toolbar.
Enter destination folder or browse to destination folder.
Check the option Extract archives to subfolders in group Miscellaneous.
Click on button OK.
In case of you want to know more about those extracting options, click before on button Help.
Or use from command line with current directory containing the *.zip files and all archive files which should be also extracted into subfolders of current directory with name of ZIP file as folder name:
"%ProgramFiles%\WinRAR\WinRAR.exe" x -ad -cfg- -ibck *.zip
How to build such a WinRAR command line?
Start WinRAR.
Click in menu Help on Help topics.
Click on tab Contents on list item Command line mode.
Click on list item Command line syntax, read this help page and copy the bold line into a text editor or into a command prompt window.
Click on tab Contents on list item Commands.
Click on list item Alphabetic commands list and replace <command> in text editor or command prompt window by most suitable command letter for the task.
Click on tab Contents on list item Switches.
Click on list item Alphabetic switches list and replace -<switch1> -<switchN> in text editor or command prompt window by those switches which are useful for the task.
Replace the rest of the WinRAR command line in text editor or command prompt window by the appropriate file and/or folder names.
The short explanation of the most important switch -ad for this task is:
-ad append archive name to destination path
As it can be seen here, WinRAR supports even a wildcard pattern as archive file name for extracting all archives files matching the pattern.
One more method exists with shell integration enabled as by default after installation of WinRAR.
Select the archive files to extract in file manager (Windows Explorer).
Click with secondary (right) mouse button on one of the selected files to open the context menu.
Open context submenu WinRAR if there is such a submenu because of enabled setting Cascaded context menus in WinRAR - Options - Settings - Integration.
Click on context menu item Extract each archive to separate folder.

SFX with 7-zip : Is it possible to run a included .bat file *before* extracting the files?

I'm creating a SFX executable with 7-zip (command line version) and the 7zsd.sfx module. My current config file looks like this :
;!#Install#!UTF-8!
Title="Test"
BeginPrompt="Test"
CancelPrompt="Do you want to cancel the extraction?"
ExtractDialogText="Please, wait..."
ExtractPathText="Please, enter the extraction path:"
ExtractTitle="Extracting..."
GUIFlags="8+32+64+256+4096"
GUIMode="1"
InstallPath="%%S"
RunProgram="test2.bat"
;!#InstallEnd#!
Is it possible to run a program before extracting the files? Currently, test2.bat is ran once the files are extracted. I'd like :
The user click "OK"
test1.bat is executed
Files are extracted
test2.bat is executed
Using WinRAR's SFX, there is a presetup option. Is there something similar using 7-zip and 7zsd.sfx?
One workaround I found is to extract the files to a temporary folder instead of the final target, run the first .bat file, xcopy the temp folder to the real target and finally run the last .bat.

How can I automate the building of this Winrar Sfx File

After building my appplication on Windows using maven (and a little bit of ant) I manually create a Winrar Sfx Installer as follows:
Select files, right click and select Add to Archive
Use Browse.. to create the archive in the folder above
Change Archive Format to Zip
Enable Create Archive Format
Select Advanced tab
Select SFX Options
Select Setup tab
Enter setup.exe into the Run after Extraction field
Select Modes tab
Enable Unpack to temporary folder
Select text and Icon tab
Enter new title
Select setup.ico from the same folder that we invoked winrar from
Select OK
Select OK
But can I automate some/all of this using Windows batch file/ Maven or ant ?
Start WinRAR, click in menu Help on Help topics and open tab Contents. You see there the list items:
Command line mode
Command line syntax
Commands
"A" - Add to archive
Switches
...
Self-extracting modules
All information you need to call WinRAR.exe with the right switches to create an SFX can be found in those help articles.
In general there are two possibilities:
You do what you have already done, but before clicking on final OK, you click on button Profiles on tab General and click on list item Save current settings to a new profile. Then you can call WinRAR.exe with switch "-cpMy SFX Profile". Read the help page for this switch.
You specify all options for creating the SFX archives directly on command line.
For the second possibility something like below can be used as template.
"%ProgramFiles%\WinRAR\WinRAR.exe" a -afzip -cfg- -ed -ep1 -k -m5 -r -tl -iicon"Path to icon file\MyApplicationInstall.ico" "-sfx%ProgramFiles%\WinRAR\Zip.sfx" "-zComment file with full path containing SFX options" "Path to Destination Folder\MyApplicationInstall.exe" "Path to files to add to archive\*"
The content for the *.txt comment file for switch -z can be copied from tab Comment of the dialog opened for creating the archive after selecting all the SFX options.
By the way: I would suggest creating RAR self-extracting archives instead of ZIP self-extracting archives as with RAR compression the EXE file with the right switches for best compression using additionally also solid archive options could be much smaller than with ZIP compression.
So you don't need a batch file or any other application to create a WinRAR SFX archive. A simple shortcut file (*.lnk) with the right command line is all you need to create the SFX archive with a double click on this shortcut whenever you want to create a new SFX for your application.

help with windows batch scripting basics - execution and calling a separate executable within the script

Newbie to windows scripting. I need help running the .bat file on the command line so I can test it.
I used Text Document as my editor to create the file (opens up also as Notepad).
I performed file "save as" (ALL FILES). If I open up cmd, I can see the file has a .txt extension (myfile.bat.txt). So if I just type in cmd myfile.bat.txt the editor opens. I am not sure how to execute this correctly.
As for the logic in my batch script, I am basically logging into a remote directory (already created the net mount) and now I want to:
run an executeable file
rename some files.
With some research, I written this so far. I have saved it as a .bat file
# echo off
echo This is a batch file to run an executable and rename some files
pause
--run executable file here, just don't know how to do it
x:
cd x:
rename fileA fileB
Any help, good tips/practice would be great. Thanks.
Type in this command in cmd window:
rename myfile.bat.txt myfile.bat
Now you can run the script by simply invoking:
myfile.bat
or
myfile
(provided there's no myfile.exe or myfile.com in the same directory).
If you need to edit the script further, you can either right click it in Explorer and choose Edit or call the editor from the command window:
notepad myfile.bat
To call a program from the script, simply add its name, if it's in the current directory:
someprogram.exe
or the name with the path, if it's somewhere else:
directory\program.exe
or
d:\directory\program.exe
If the name or the path contain spaces, be sure to enclose the entire name & path string in double quotes:
"d:\directory\program name.exe"
you can just type the full name of the program
eg
"c:\program dir\program.exe"
or you can add the program directory to your path environment variable
set PATH=%PATH%;"c:\program dir"
and just type the program name
program
you can also edit your PATH variable in windows http://support.microsoft.com/kb/310519
NOTE: When you save the file in notepad, you want to save it as filename.BAT and select All Files from the second dropdown. If you don't it still gets saved as a .TXT.
A couple of command to consider:
CSCRIPT cscript /? in CMD
START http://ss64.com/nt/start.html
If you're doing say a VBSCRIPT use CSCRIPT to start it. If you're trying to execute another BATCH script or an EXE, use START

creating an icon of a shortcut of a batch file using nsis installer

I need to set an icon for my batch file OR for the shortcut of my batch file , using the nsis installer.
Can an icon be set only of a shortcut , or can i set the icon of the main batch file whose shortcut needs to be created.
The following code isn't working:
I have a folder MyAccountSoftware, my installer will compile the files of this folder into the exe file.
This folder has these two files :-
---MyAccountSoftware
|______Account.BAT
|______Account.ico
SetOutPath $INSTDIR\
File "MyAccountSoftware\Account.BAT"
CreateShortCut "$INSTDIR\Account.lnk" "$INSTDIR\Account.BAT" "$INSTDIR\Account.ico"
This code, just copies the file Account.BAT into the required $INSTDIR, and creates a shortcut -
Account.Ink in the $INSTDIR, but doesn't set the icon of the Shortcut.
Please help.
Batch files cannot have custom icons. When creating the shortcut, even if you don't need a parameter you still need to provide a empty string:
CreateShortCut "$INSTDIR\Account.lnk" "$INSTDIR\Account.BAT" "" "$INSTDIR\Account.ico"

Resources