Jump to content

Just another RunOnceEx project


Recommended Posts

Hi,

I've created just another RunOnceEx.cmd. Why, you may ask, well, a couple of reasons:

  • I wanted to eliminate mistakes in the syntax for adding registry keys, I sometimes "forget" to escape double quotes, or made mistakes with REG ADD %KEY%\001, typed KET instead of KEY, etc ...
  • The ability to install different apps on a real machine instead of a virtual machine. Some software I install on my real machine, will not install completely silent (PCTV Stereo from Pinnacle), I don't use something like AutoIt. BTW there is no use to install PCTV in a virtual machine.
  • I also wanted something with which I could reconfigure my apps easier.

And this is the result.

A command file (RunOnceEx.cmd) and a configuration file (RunOnceEx.txt = sort of ini-file).

The syntax:

RunOnceEx.cmd [ TEST ] [ CDdrive-letter.DRV ] [ CFGFILE.TXT ]

TEST         : (case sensitive) Display what will happen, instead of adding registry entries.

Letter.DRV   : If you know how to change your CDdrive-letter use this 1. Otherwise don't touch it.

CFGFILE.TXT  : Select a different configuration file. Otherwise the commandfile will look for a RunOnceEx.txt in the same directory as the commandfile and if available A:\RunOnceEx.txt, where the last one found will be used.

Now what will it do, the command file will process the configuration file.

  • Skip all lines starting with a #. If # is not the first character it will be part of the commandline, registry key or variable.
  • Read the CONFIG section (case sensitive), set some variables and add a few registry keys.
  • Read the other sections:
    1. Add section title to registry
    2. Add the following lines (till the next section) as commands to the registry

Configuration file summary:

[CONFIG]     : Config section (case sensitive)

KEY          : Override the default KEY variable. The base key to add/update in the registry.

NR           : Override the default NR variable. The first number (minus 1) to use. The last part of the registry subkey.

REG_KEYS     : Override the default REG_KEYS variable. A list of KEYS (within the config section) which should be added to the registry, others will be set as variables.

REG_KEY.type : A key which should be added to the registry of type ".type". If type is omitted it is added as a string.

TITLE        : The title of the RunOnceEx window.

VAR_REPLACE  : A list of variables which “names” should be converted to there “values".

USER Vars    : Any number of variables you want to use.

[section X]  : Start a new section (Section X, case insensitive)

# Comment 1

Command 1    : First command for Section X

# Comment 2

Command 2    : Second command for Section X

Command x    : x-th command for Section X

[section Y]  : Start a new section (Section Y, case insensitive)

# Comment 3

Command 1    : First command for Section Y

# Comment 4

Command x    : x-th command for Section Y

Here is the command file: RunOnceEx.cmd

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

REM Set variables with default values
SET CDROM=%~d0
SET KEY=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx
SET REG_KEYS=TITLE
SET NR=0
SET TEST=

REM Check commandline options
FOR %%F IN (%*) DO @(
REM In testmode var TEST is set, otherwise it is empty
IF "%%~F"=="TEST" SET TEST=ECHO
REM If you know how to change your CDdrive-letter use this 1
IF /I "X%%~xF"=="X.DRV" SET CDROM=%%~nF:
REM Set a alternative configuration file
IF /I "X%%~xF"=="X.TXT" IF EXIST "%%~F" SET CFGFILE=%%~F
)

REM If %CFGFILE% is not set, check for RunOnceEx.txt in current dir
REM and A:\RunOnceEx.txt, set CFGFILE to the last one found.
IF "X%CFGFILE%"=="X" (
FOR %%F IN ("%~dpn0.txt" "A:\%~n0.txt") DO @(
REM Set CFGFILE to %%~F and not %%~D. %%D does not contain drive
REM and directory info and %%F does.
FOR /F %%D IN ('DIR /B %%F') DO @SET CFGFILE=%%~F
)
)

REM Get configuration stuff (skip other sections)
FOR /F "DELIMS== TOKENS=1,*" %%F IN (%CFGFILE%) DO @(
REM Make sure !REG_KEYS! is set, further on we use this one and not %REG_KEYS%
IF "X!REG_KEYS!"=="X" SET REG_KEYS=%REG_KEYS%
REM Set FIELD1 So we can check things properly
SET FIELD1=%%F
REM Skip lines starting with a #
IF NOT "X!FIELD1:~0,1!"=="X#" (
REM Checking for Sections
IF "X!FIELD1!"=="X[!FIELD1:~1,-1!]" (
SET SECTION=!FIELD1:~1,-1!
) ELSE (
IF !SECTION!==CONFIG (
REM Check if entry should be added to the registry
FOR %%R IN (!REG_KEYS!) DO @(
IF %%R==%%~nF (
SET REG_TYPE=%%~xF
IF NOT "X!REG_TYPE!"=="X" SET REG_TYPE=!REG_TYPE:.=/T REG_!
%TEST% REG ADD !KEY! /V "%%~nF" /D "%%G" !REG_TYPE! /F
SET REG=Y
)
)
REM If entry is not added to the registry set it as a variable
IF NOT !REG!==Y SET %%F=%%G
SET REG=
)
)
)
)

REM Get all other sections (skip CONFIG section)
FOR /F "DELIMS=" %%F IN (%CFGFILE%) DO @(
SET FIELD1=%%F
IF NOT "X!FIELD1:~0,1!"=="X#" (
IF "X!FIELD1!"=="X[!FIELD1:~1,-1!]" (
SET SECTION=!FIELD1:~1,-1!
IF NOT !SECTION!==CONFIG (
REM (Re)set variables NR & COUNT And add section to Registry
IF !NR! LSS 100 SET NR=!NR:~-2!
IF !NR! LSS 10 SET NR=!NR:~-1!
SET /A NR=!NR! + 1
IF !NR! LSS 10 SET NR=0!NR!
IF !NR! LSS 100 SET NR=0!NR!
SET COUNT=0
IF NOT "X%TEST%"=="X" %TEST%.
%TEST% REG ADD !KEY!\!NR! /VE /D "!SECTION!" /F
)
) ELSE (
IF NOT !SECTION!==CONFIG (
REM Manipulate COUNT variable
IF !COUNT! LSS 10 SET COUNT=!COUNT:~-1!
SET /A COUNT=!COUNT! + 1
IF !COUNT! LSS 10 SET COUNT=0!COUNT!
REM Set COMMAND and "manipulate" it
SET COMMAND=%%F
SET COMMAND=!COMMAND:"=\"!
FOR %%R IN (%VAR_REPLACE%) DO @(
CALL :SET_CMD COMMAND "%%%%%%R%%%%" "%%%%R%%"
)
REM Add it to the registry
%TEST% REG ADD !KEY!\!NR! /V !COUNT! /D "!COMMAND!" /F
)
)
)
)
GOTO END

:SET_CMD
REM Here are variables defined in VAR_REPLACE converted from %var% to it's value
SET %~1=!%~1:%~2=%~3!
:END

And here is an example configfile: RunOnceEx.txt

[CONFIG]
# This section uses = as a field separator
KEY=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx
# NR: The first number (minus 1) to use for the registry key
NR=0
REG_KEYS=TITLE FLAGS
# The title of the "runonceex window"
TITLE=Install Apps & Modify Settings
# FLAGS: Win2k uses this for logging errors and command execution (or so I've read)
# I couldn't find anything about xp though.
FLAGS.dword=48
# VAR_REPLACE
VAR_REPLACE=CDROM DEST SYSTEMDRIVE SYSTEMROOT
# User defined variables
DEST=%SYSTEMDRIVE%\Apps

[AVG Antivirus]
# Install AVG Antivirus Free version
%CDROM%\Install\AVG\AVG-AntiVirus.exe /HIDE /DONT_START_APPS /NO_WELCOME /NO_AVGW_STARTUP /QUIT_IF_INSTALLED /TARGET_DIR "%DEST%\AVG\Antivirus"
# Update virus definition files
%DEST%\AVG\Antivirus\avgw.exe /UPDATE /UPDDIR=%CDROM%\Install\AVG\binfiles

[ZoneAlarm]
%CDROM%\Install\ZoneAlarm\ZoneAlarm.exe /s /noreboot /installdir "%DEST%"

[Internet Applications]
# Install Java
%CDROM%\Install\Java\Java.msi /qn INSTALLDIR="%DEST%\Java" NETSCAPE6=0 WEBSTARTICON=0 JAVAUPDATE=0
# Install Opera
%CDROM%\Install\Opera\Opera.msi /qr INSTALLDIR="%DEST%\Opera" MULTI_USER_SETTING=0

[Office/Document Applications]
# OpenOffice.org Version 2.3
%CDROM%\Install\OpenOffice.org\OpenOfficeorg23.msi /qn INSTALLLOCATION="%DEST%\OpenOffice.org" SELECT_WORD=1 SELECT_EXCEL=1 SELECT_POWERPOINT=1
# Adobe Reader
%CDROM%\Install\AdobeReader\AdobeReader.msi /qn INSTALLDIR="%DEST%\AdobeReader"

[Image Applications]
# ImageMagick
%CDROM%\Install\ImageMagick\ImageMagick.exe /DIR="%DEST%\ImageMagick" /MERGETASKS="^!desktopicon" /VERYSILENT /SP-

[Disk and CD/DVD-image Applications]
# Diskeeper
%CDROM%\Install\Diskeeper\Diskeeper.msi /qn INSTALLDIR="%DEST%\Diskeeper"
# Daemon Tools
%CDROM%\Install\DaemonTools\DaemonTools.msi /qn TARGETDIR="%DEST%\DaemonTools" INSTALLDIR="%DEST%\DaemonTools" REBOOT=REALLYSUPPRESS

[Reboot]
SHUTDOWN.EXE -t 30 -r

[CONFIG] Section explained (case sensitive)

KEY          : If exists it overrides the default value for KEY. The base key to add/update in the registry. Default is set to HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx.

NR           : The first number to use (minus 1) for the (first)section subkey. In the example above "AVG Antivirus" is the first subkey. If you have multiple (I haven't experimented with this). It should be at least equal to the number of sections processed in all previous configfiles. Default is set to 0.

REG_KEYS     : If exists it overrides the default value for REG_KEYS. It contains a list of KEYS which should be added to the registry instead of being set as variables. Use only the basename. Default is set to TITLE. See also REG_KEY.type.

REG_KEY.type : An REG_KEY which should be added to the registry. If the REG_KEY doesn't contain a ".type", it will be added to the registry as a string (REG_SZ). Type can be set to dword, binary, etc, etc..

In the above configfile FLAGS (without ".type") is added to REG_KEYS. So when the command file processes the line with FLAGS.dword, it will add "FLAGS" to the registry, it's type is "REG_DWORD", and it's value = 48 (=numeric, HEX = 0x00000030).

TITLE        : The window title of the RunOnceEx process.

VAR_REPLACE  : Contains a list of variables which should be replaced with their values before the commands are added to the registry. When reading from a text file %variables% aren't converted to their corresponding values by the shell (CMD.EXE). And the RunOnceEx process doesn't understand variables. So as a workaround, add all variables used in the configfile to VAR_REPLACE. There is one other thing. If a variable contains others (%DEST% => %SYSTEMDRIVE%\Apps), the variable DEST should be put before SYSTEMDRIVE in the list.

USER VARS    : Any number of variables you want to use, and are not defined by default. For example: DEST=%SYSTEMDRIVE%\Apps (for destination).

Examples:

RunOnceEx.cmd                              Run in normal mode, with 1 of it's default configfiles (RunOnceEx.txt in same directory as RunOnceEx.cmd or A:\RunOnceEx.txt)

RunOnceEx.cmd TEST                         Run in test mode with it's default configfile.

RunOnceEx.cmd A:\ROE_%COMPUTERNAME%.txt    Run in normal mode, with an alternative configfile.

Notes:

  1. I think that most commands you can execute on the commandline you can add to the configfile without much trouble. There are several characters which needs to be escaped though:
    - to use a &, | or !, use a ^ before the character, thus ^&, ^| or ^!
    there may be other characters, but I'm not aware of them. The command file will escape the double quotes
  2. If you run in TEST mode you can redirect the output and create a "regular" RunOnceEx.cmd.
  3. The variable CDROM will be set to the drive-letter on which the commandfile is executed.
  4. It's a little slower than a regular RunOnceEx.cmd, because it has to process a configfile into commands.

Hint:

If you're worried about someone copying/stealing your CD. Put a minimal configfile on CD, without any product/license info in it. And keep a configfile on a floppy which contains a list of all apps you want to install including procuct/license info.

Give it a try. Put a configfile in the same directory as the command file and put a configfile on a floppy. Change in both files the TITLE, so you can seperate them, and run the command in test mode. If you see variables in the output from test-mode, you might have to look at VAR_REPLACE again, and add variable-names or put the one further to the front of the list.

The attached zipfile contains 3 files: RunOnceEx.cmd, RunOnceEx.txt & "Just another RunonceEx.cmd.rtf"

EDIT (Apr 12th): Updated the text a little, tried to make it more readable.

EDIT (Apr 13th): After edit on the 12th backslashes were missing; put the code in a codebox

RunOnceEx.zip

Edited by jjvs
Link to comment
Share on other sites


If you're worried about someone copying/stealing your CD. Put a minimal configfile on CD, without any product/license info in it. And keep a configfile on a floppy which contains a list of all apps you want to install including procuct/license info.

They can goes to two way.

- Reformat the computer and give it away, keeping the disc themselves.

- They can put up or shut up :thumbup

In bonus, up yours. :rolleyes:

Anyway, awesome job on the thread, but I uses RunOnceEx.cmd and cmdlines.txt inside $OEM$, working quite well. :)

Link to comment
Share on other sites

  • 2 weeks later...
Anyway, awesome job on the thread, but I uses RunOnceEx.cmd and cmdlines.txt inside $OEM$, working quite well.

I store my RunOnceEx.cmd together with a minimal/generic RunOnceEx.txt in ..\Install\Other. But I also call it via the cmdlines.txt process. This will install only a couple of apps and not apply any regtweaks, or other things.

When I install my computer I've got an configfile stored on floppy, which the commandfile will pickup (as long as no alternative configfile is specified on the commandline) and use it instead of the one on CD. This will install more apps and will apply numorous regtweaks etc.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...