Jump to content

Small script to help adding applications.


Recommended Posts

[uPDATE]

The information in this post isn't up-to-date, please check this post for the most recent version of my script.

[/uPDATE]

Hello! I created a small script that makes the maintaning and adding of applications to your unattended disc a lot easier.

Normally, most people use this sort of scripts to install applications:

echo.
echo Installing Kaspersky Anti-virus 4.5
"%SystemDrive%\apps\KAV\Setup.exe" /S /N

echo.
echo Installing Winrar 3.12
"%SystemDrive%\apps\Winarar\wrar341.exe" /s

Ofcourse there's nothing wrong with this.. only this requires a lot of manual work and typing. So instead of adding applications manually, i created a script that runs at "install time" and automatically checks for applications to be installed at a given directory (in this case "%SystemDrive%\apps").:

@echo off

for /R "%SystemDrive%\apps" %%i IN (.) DO (
 if EXIST "%%~fi"\!commands.cmd (
   echo.
   echo Installing "%%~fi"
   pushd "%%~fi"
   call !commands.cmd
   popd
 )
)

How? It scans all subdirectories and in each directory it checks for a "!commands.cmd" file and executes it. So [deleting an application / adding an application / changing the dir-structure] won't require to change your install-scripts!

The "!commands.cmd" file should only contain Setup.exe /S /N (in the case for Kaspersky). Because the script temporary changes the current directory to the application-directory you won't have to use absolute paths.

You could use this script in this dir-structure for example:

%SystemDrive%
   |
   |---Apps
        |
        |---Archiving
        |       |
        |       |---Powerarchiver 5.4
        |       |---Winrar 3.41
        |       |---Winzip 8
        |
        |---Graphics
                |
                |---IrfanView 5.3
                |---Xnview 2.4

Now only put a "!commands.cmd" file in a directory that you want to install automatically; so for winrar this file contains only wrar341.exe /s. (Also this way, if you would just double-click the cmd-file from explorer or something.. it should install the application too.) The cmd-file could also contain the regular file-exist-checks such as with the ATI control panel or the Nvidia sound-panel.

Applications are installed in the order they appear in de directory structure. So if you have an application that needs to be installed before others, you should make sure that directory appears first in the directory structure.

Edited by Afterdawn
Link to comment
Share on other sites


neat idea... for a cd rom install or automated install where you would use the directory structure to sequence the install.

I also use a script to map a unc path. so that you can just click on a file and it installs... if a drive needs to be mapped to do the install.. which could be chained together with this script to make this script work off of a network share.

@echo off
cls
if not exist o2k3.msi goto mapdrive

:install
echo.
echo installing Office 2003
echo.
msiexec  /i o2k3\PRO11.MSI transform=o2k3\Pro11.MST -qb
goto :eof

:exit
exit

:mapdrive
echo.
echo install directory is on a UNC Share .. Mapping drive
echo.
setlocal
set uncinstallpath=%~p0
set uncinstallpath=%uncinstallpath:~0,-1%
net use * "\\%uncinstallpath%" > uncdrive.txt
FOR /F "eol=; tokens=2 delims=, " %%i in (uncdrive.txt) do call :changedrive %%i

:changedrive
if not exist %1\*.* goto :eof
echo changing drive to %1
%1
call :install
echo unmapping drive %1
C:
net use %1 /d /y
set uncinstallpath=
goto exit

Link to comment
Share on other sites

but you still have to do the brute force of finding the switches and such :P

I could have sworn I saw something similar to this before....oh well...

If somebody create a universal program for command-line switch installer then the Application Switches forum would be useless, but it's not for tomorrow :P

And for seeing that before, that's for sure.

I have made a batch like this for testing purpose. It a solution having the advantage to easily adding programs by adding a folder and a CMD

Personnally I would remove the POPD (useless) command and replace the PUSHD command by CD /D. And the ECHO command would be more at the right place in the program CMD, but it's my point of view ;)

Reinventing the weel is not an easy task :lol:

Sorry Afterdawn, I was feeling like this today.

Link to comment
Share on other sites

@jdoe:

The POPD instruction probably isn't needed here.. but I use this script in another larger script-file, so when the for-loop finishes i want to make sure the active directory is restored. Btw, CD doesn't understand network-paths! PUSHD automatically creates a temporary (ie Z:) network mapping!

Also.. if ya would put the ECHO lines in the cmd-file... then it would almost defeat the purpose of my script!

@staples

I'm am sure you can replace all that networkletter mapping/changing with a simple PUSHD command! Ah well.. maybe you'll need the net use ... command too.

Link to comment
Share on other sites

The POPD instruction probably isn't needed here.. but I use this script in another larger script-file, so when the for-loop finishes i want to make sure the active directory is restored.

Yeah, that's what I thought. But it could have been...

SET CURRENTPATH=%CD%

FOR Bla Bla Bla

CD %CURRENTPATH%

Nevermind

Link to comment
Share on other sites

Or you could just do it like this....

for /f %%i IN ('dir %systemdrive%\apps /b') Do @echo start "" /wait %systemdrive%\apps\%%i >>%systemdrive%\apps\apps.cmd

call apps.cmd

or even easier....
for /f %%i IN ('dir %systemdrive%\apps /b') Do @echo start "" /wait %systemdrive%\apps\%%i

been doin' it this way myself well over a year...

you can check an old post of mine and see the many ways I used to use it...

http://www.osnn.net/forum/archive/index.php/t-36648.html

Link to comment
Share on other sites

@ un4given1:

No you cannot do it that way!

The cmd-files do not contain absolute paths (because you can add programs quicker that way!)

@ everybody who thinks the pops instruction isn't needed!:

Who cares!!! You won't notice it if you removed it! Maybe your unattended installations is 14 nanoseconds faster!!!! Anyway I changed it a bit:

[uPDATE: Please check http://www.msfn.org/board/index.php?showto...ndpost&p=251941 for the most recent version.[/uPDATE]

set installDir=\\10.0.0.152\install
net use %installDir% /user:username password
if NOT %ERRORLEVEL%==0 (
 echo. Cannot connect to %installDir%
) else (
 pushd %installDir%
 for /R %%i IN (.) DO (
   if EXIST "%%~fi"\!commands.cmd (
     echo.
     echo Installing "%%~fi"
     cd "%%~fi"
     call !commands.cmd
   )
 )
 popd
)

Now it installs from a network drive.. if the server is available!

And now PUSHD is mandatory! Because it automatically maps the first available drive (ie Z:). CD doesn't understand direct networkpaths (it does for mapped ones of course). Also if you PUSHD you gotta POPD :D otherwise the stack only grows!

Edited by Afterdawn
Link to comment
Share on other sites

Afterdawn, I do something pretty similar myself.

In my $OEM$ directory I have:

CMDLINES.TXT:

[Commands]
"CMDLINES.BAT"

CMDLINES.BAT contains:

@FOR /F "tokens=*" %%i IN ('DIR /A /B /S "%~dp0INSTALL.BAT" ^| FIND /V "$1"') DO START "" /MIN /WAIT CMD.EXE /C "%%i"

(List all files matching "INSTALL.BAT", but we don't want to go into the $1 directory for stuff we're installing during the GUI portion of setup, so exclude it using FIND /V. %~dp0 comes in handy, it points to the directory where the BAT file is being executed from, so CMDLINES.BAT will work properly no matter where its called from.)

So basically I never have to modify CMDLINES.TXT to add new programs and whatnot. All I have to do is make a directory for the program, and make an INSTALL.BAT with all the commands to install it silently, etc. The main batch file does the rest.

And for GuiRunOnce it's pretty much the same thing:

WINNT.SIF:

[GuiRunOnce]
   Command1="%SystemDrive%\RUNONCE\RUNONCE.BAT"

RUNONCE.BAT:

@FOR /F "tokens=*" %%i IN ('DIR /A /B /S "%~dp0INSTALL.BAT"') DO START "" /MIN /WAIT CMD.EXE /C "%%i"

Link to comment
Share on other sites

@ un4given1:

No you cannot do it that way!

The cmd-files do not contain absolute paths (because you can add programs quicker that way!)

@ everybody who thinks the pops instruction isn't needed!:

Who cares!!! You won't notice it if you removed it! Maybe your unattended installations is 14 nanoseconds faster!!!!  Anyway I changed it a bit:

set installDir=\\10.0.0.152\install
net use %installDir% /user:username password
if NOT ERRORLEVEL 0 (
 echo. Cannot connect to %installDir%
) else (
 pushd %installDir%
 for /R %%i IN (.) DO (
   if EXIST "%%~fi"\!commands.cmd (
     echo.
     echo Installing "%%~fi"
     cd "%%~fi"
     call !commands.cmd
   )
 )
 popd
)

Now it installs from a network drive.. if the server is available!

And now PUSHD is mandatory! Because it automatically maps the first available drive (ie Z:). CD doesn't understand direct networkpaths (it does for mapped ones of course). Also if you PUSHD you gotta POPD :D otherwise the stack only grows!

I'm interested in this at what point durring the install is this usable? For me it has to be durring the cmdlines.txt portion of the install. That way anything installed is added to the default user profile and will work for all users.

I'm only curious because I'm unsure if netwroking has been setup at htat point which means that using this method would not be usable for me.

Link to comment
Share on other sites

@ un4given1:

No you cannot do it that way!

The cmd-files do not contain absolute paths (because you can add programs quicker that way!)

You can't? Oh, my bad... I guess the 1500+ PCs I used this for were all faking it, huh?

I meant it doesn't work in my situation! Your one isn't that flexible!

Well.. never mind!

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...