How to perfom a silent installation of WinRAR.
Files needed:
1.
wrar300.exe - winrar distribution archive.
(Optional)
2.
RARREG.KEY - registration code.
3.
rarlng.rar - from
rarlabs.com (contains
Setup.SFX and
setup.s)
A. Silent Installation
wrar300.exe /sB. Registered Installation
This just requires getting
RARREG.KEY into the WinRAR program folder. It can be copied before running the installation or a new distribution archive can be created which includes
RARREG.KEY. As described in the
rarlng.rar help files, its easy to create an archive which is just like the original download (without the digital signature). To do this you will need the two files,
Setup.SFX and
setup.s, from the
rarlng.rar archive:
1. Extract your distribution to a temporary folder like \"wrar300\".
2. Copy
RARREG.KEY into the folder.
3. Having WinRAR already installed, the following command will recreate the distribution:
\"< program folder >winrar.exe\" a -r -ep1 -cfg- -s -m5 -z< setup.s > -sfx< Setup.SFX > < archive name > < files to add >For example with
Setup.SFX and
setup.s in the folder just above \"wrar300\":
\"c:program fileswinrarwinrar\" a -r -ep1 -cfg- -s -m5 -zsetup.s -sfxSetup.SFX wrar300 wrar300*.*C.I Preconfigured Settings
To preconfigure WinRAR settings, such as a cascaded context menu, the appropriate registry entries need to be added. The following is a .reg file that enables cascaded menus, sets some file association (ones not set are used by winzip), and disables the desktop and start menu icons:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USERSoftwareWinRARSetup]
\"ShellExt\"=dword:00000001
\"CascadedMenu\"=dword:00000001
\"MenuIcons\"=dword:00000001
[HKEY_CURRENT_USERSoftwareWinRARSetup.ace]
\"Set\"=dword:00000001
[HKEY_CURRENT_USERSoftwareWinRARSetup.arj]
\"Set\"=dword:00000000
[HKEY_CURRENT_USERSoftwareWinRARSetup.bz]
[HKEY_CURRENT_USERSoftwareWinRARSetup.bz2]
\"Set\"=dword:00000001
[HKEY_CURRENT_USERSoftwareWinRARSetup.cab]
\"Set\"=dword:00000000
[HKEY_CURRENT_USERSoftwareWinRARSetup.gz]
\"Set\"=dword:00000000
[HKEY_CURRENT_USERSoftwareWinRARSetup.jar]
\"Set\"=dword:00000001
[HKEY_CURRENT_USERSoftwareWinRARSetup.lzh]
\"Set\"=dword:00000000
[HKEY_CURRENT_USERSoftwareWinRARSetup.rar]
\"Set\"=dword:00000001
[HKEY_CURRENT_USERSoftwareWinRARSetup.tar]
\"Set\"=dword:00000000
[HKEY_CURRENT_USERSoftwareWinRARSetup.tbz]
[HKEY_CURRENT_USERSoftwareWinRARSetup.tbz2]
[HKEY_CURRENT_USERSoftwareWinRARSetup.uue]
\"Set\"=dword:00000000
[HKEY_CURRENT_USERSoftwareWinRARSetup.zip]
\"Set\"=dword:00000000
[HKEY_CURRENT_USERSoftwareWinRARSetupLinks]
\"Desktop\"=dword:00000000
\"StartMenu\"=dword:00000000
\"Programs\"=dword:00000001
So a sample batch file that installs WinRAR might look like (
wrprep.reg is the file above):
@ECHO OFF
TITLE WinRAR Setup
ECHO Installing WinRAR 3.0 . . .
CD \"%~dp0\"
CMD /Q /U /C >>wrcfg.reg ECHO.\"DisplayIcon\"=\"%SystemDrive%Program FilesWinRARwinRAR.exe,0\"
CMD /Q /U /C >>wrcfg.reg ECHO.\"InstallLocation\"=\"%SystemDrive%Program FilesWinRAR\"
regedit.exe /s .wrprep.reg
wrar300.exe /s
regedit.exe /s .wrcfg.reg
ECHO Done.
Here another file,
wrcfg.reg, is used to fancy up the WinRAR entry in \"AddRemove Programs\". Two lines are appended to this file before it is loaded because the paths need the drive letter. The file
wrcfg.reg looks like this:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionUninstallWinRAR archiver]
\"DisplayName\"=\"WinRAR\"
\"DisplayVersion\"=\" 3.00\"
\"Publisher\"=\"Eugene Roshal\"
\"URLInfoAbout\"=\"http://www.rarlab.com\"
\"URLUpdateInfo\"=\"http://www.rarlab.com\"
\"VersionMajor\"=dword:00000003
\"VersionMinor\"=dword:00000000
C.II Preconfigured Settings for All Users
The sample batch file above only changes settings for the currently logged in user. To make all current and future users also have these settings as default, the registry entries need to be added for each user and to the default profile. Each user\'s registry hive,
NTUSER.DAT, is located in their profile directory and the default profile is located in the \"Default User\" directory. So these hives each need to be loaded and then the above registry keys need to be added. This is of course easiest to do during a clean install before any users have been added.
One Method:
Here is
a method using the
Cmdlines.txt and
winnt.sif functionality. It is less sophisticated than the next way and doesnt require reg.exe.
First thing to know is that during GUI mode setup, Windows uses the default user profile and thus all user specific changes made at this time will be present for all future users, since a new user\'s initial profile is just copied from the default profile when they first logon. So to load the settings for WinRAR, with
wrprep.cfg in the $OEM$ folder, add the following line to
Cmdlines.txt:
[Commands]
\"regedit.exe /s .wrprep.reg\"
However, it gets more interesting. Actually, HKEY_CURRENT_USER is mapped to the HKEY_USERS.DEFAULT key, which is the profile used when NO user is logged on (i.e. at the logon prompt); this hive is stored in the
system32configdefault file. At the end of GUI mode setup, when setup is saving settings, it creates the default user profile by saving the current user profile to
Default UserNTUSER.DAT. So while all the settings will be present for all future users, they will also
REMAIN in this .DEFAULT profile, which may or may not be desireable. If needed just delete the entries from the .DEFAULT key after the default profile is saved.
This can be done in a [GUIRunOnce] command or it can be done at the end of GUI mode setup right after settings are saved. To do this requires setting the UserExecute parameter to the appropriate command line in the
winnt.sif answer file (undocumented?). To run a command after setup has saved settings, add a line to
winnt.sif like:
[SetupParams]
UserExecute=\"%SystemDrive%$WIN_NT$.~LS$OEM$ProfilesRemove.bat\"
Here,
Remove.bat might look like:
@ECHO OFF
CD \"%~dp0\"
%SystemRoot%regedit.exe /s .RemovWin.reg .RemovNet.reg .RemovVid.reg .RemovApp.reg
and
RemovApp.reg contains the lines:
Windows Registry Editor Version 5.00
[-HKEY_CURRENT_USERSoftwareAdobe]
[-HKEY_CURRENT_USERSoftwareNico Mak Computing]
[-HKEY_CURRENT_USERSoftwareWinZip Computing]
[-HKEY_CURRENT_USERSoftwareWinRAR]
When loaded, this deletes the keys (that had just previously been added) from the .DEFAULT profile. But since this is after the default profile has been saved, the settings will be intact for all users including the admin (Note: the administrator profile is created at the first logon).
Another Method:
Another way is to run the batch file as a [GUIRunOnce] command and add some lines to it like:
SETLOCAL
SET tmpKey=HKUDefault
SET dirKey=\"HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionProfileList\" /v ProfilesDirectory
CD \"%~dp0\"
FOR /F \"skip=1 tokens=2*\" %%X IN (\'reg.exe QUERY %dirKey%\') DO FOR /F \"delims=\" %%Z IN (\'ECHO %%Y\') DO SET pdir=%%Z
ECHO Configuring Default User. . .
reg.exe LOAD %tmpKey% \"%pdir%Default UserNTUSER.DAT\"
reg.exe IMPORT \"winrar.reg\"
reg.exe UNLOAD %tmpKey%
ENDLOCAL
This uses
reg.exe from the resource kit. It first queries the location of the profiles directory from the registry and then loads the default profile into the \"HKUDefault\" key (arbitrary name). After loading the entries in
winrar.reg, it then unloads the hive. Here,
winrar.reg would look just like the
wrprep.reg above, except it would point to the key that the hive was loaded into, for example:
Windows Registry Editor Version 5.00
[HKEY_USERSDefaultSoftwareWinRAR]
[HKEY_USERSDefaultSoftwareWinRARSetup]
\"ShellExt\"=dword:00000001
\"CascadedMenu\"=dword:00000001
\"MenuIcons\"=dword:00000001
.
.
.
I have also been able to create similar unattended installations for Winzip and Acrobat Reader if anyone is interested.