|
Answer» I'm creating a batch script that will automate the slipstreaming process for my large collection of various Windows CDs. Originally, my syntax was: set cmdswitches="/s:%directory%" /U
set directory=windistro1 %executable% %cmdswitches% set directory=windistro2 %executable% %cmdswitches%
Where windistro# is the correct path of the Windows CD. My second try was %%directory%%, which didn't work either. It wouldn't be hard except I'm calling these variables from another batch file so that a user can input their command line switches without having to see/edit the CODE for the main batch file. Thus, this solution isn't exactly feasible:
set directory=windistro1 set cmdswitches="/s:%directory%" %executable% %cmdswitches% set directory=windistro2 set cmdswitches="/s:%directory%" %executable% %cmdswitches%
Your help is appreciated =) OverkillMore questions than answers.
If windistro# contains a value from the environment, then should it not be set directory=%windistro1% or set directory=%windistro2%
Where did %executable% come from and does it contain a valid value? I'm guessing the %cmdswitches% values are valid for this executable.
It also depends on how the second batch file is called. If the variables are passed along the command line, the values would be referenced by the command line arguments %1-%9. You'd probably get away with using the names of the variables however, since the environment would be passed along to the called file.
Let us know. yes, i meant to say %windistro#%.
%executable% is the path to a windows update, like WinInstaller31v2.exe %cmdswitches% are valid - the problem is that %directory% needs to be replaced by %windistro----% (i used a four character shorthand, like xppc = xp pro corporate.
the second batch file is called using: COPY "%varsini%" "vars.bat" > STFU CALL vars.bat
varsini is a valid filename; i have a check built into the batch file using if exist and if not exist commands. it is called rather early in the batch file. I want it to define the variables n, xppc, p, cmdswitches, and others irrelevant to this question. p is what i've been using for the %executable% (i just said %executable% because i thought it would be easier to understand ).
IF "%xppc%"=="skip" (GOTO skipxppc) ECHO Integrating %n% with Windows XP Professional Corporate... SET directory=%xppc% %p% %cmdswitches% ECHO Complete :skipxppc IF "%process%"=="xppc" (GOTO endxp)I'm probably having a senior moment, but you've not mentioned where an error appears and what it may be. The COPY "%varsini%" "vars.bat" > STFU is suspect if vars.bat exists; the overwrite question will be in the STFU file and the copy operation will come to a grinding halt.
By setting variables to values, they reside in the environment space and can be accessed by name from vars.bat provided they are enclosed with % symbols.
Perhaps if we could see the entire file(s) and where specifically you're having a problem, this would be a lot easier.
First, thanks for all the help sidewinder =) I appreciate it - I would get nothing done if you and people like you didn't at least try to pull me out of the quicksand
I'm trying to avoid posting the whole main file because it contains over 650 non-commented, non-blank lines, but I have a section in it devoted to cleaning up the files created by the install so your suggestion about the copy command doesn't apply
What my problem is: *My batch file is supposed to be providing a solution to "I have one or more Windows updates that I need to slipstream with one or more Windows CDs that I have copied to my hard drive". *I use a four letter code, like xppc, to represent a single distribution of Windows *There are 19 potential different distributions that I am APPLYING this update to *That four letter code is defined with some value, like C:\WINDVD2\SETUP\XP\XPPC in vars.bat *The variable cmdswitches is given a value in vars.bat and sets the switches for the executable %p% *I want to use the switch /s:%directory% where %directory% is different for each distribution of Windows, and is set by the four letter code.
This is what I want to have happen. directory has to be defined after cmdswitches, but %cmdswitches% has to contain %directory%. I tried setting cmdswitches to /s:%%directory%% then later using set cmdswitches=%cmdswitches% but that didn't work.
Code: [Select]set xppc=xppcpath set cmdswitches=/s:%directory% set p=somefile.exe
SET directory=%xppc% %p% %cmdswitches%
Here's the vars.bat file I'm using: Code: [Select]:: Color of DOS window :: For help visit http://malektips.com/xp_dos_0015.html color 0A
:: Name of update set n=Windows Installer 3.1 v2
:: Path of update set p=C:\WinDVD2\INTEGR8\WindowsInstaller31v2.exe
:: Switches to apply to installation set cmdswitches="/s:%directory%"
:: Full path of the directory containing the i386 folder :: If you wish to skip the installation, give the variable the value skip. :: For example, to skip Windows XP MEDIA Center & Tablet PC: :: set xpmt=skip :: DO NOT change the variable names.
:: Windows 2000 set as2k=C:\windvd2\setup\2K\Advanced set dc2k=C:\windvd2\setup\2K\Datacenter set pr2k=C:\windvd2\setup\2K\Professional set sv2k=C:\windvd2\setup\2K\Server
:: Windows XP set xphc=C:\windvd2\setup\xp\HomeCorp set xpho=C:\windvd2\setup\xp\HomeOEM set xphr=C:\windvd2\setup\xp\HomeRetail set xppc=C:\windvd2\setup\xp\ProCorp set xppo=C:\windvd2\setup\xp\ProOEM set xppr=C:\windvd2\setup\xp\ProRetail set xpmt=C:\windvd2\setup\xp\MCETAB
:: Windows Server 2003 set dc23=C:\windvd2\setup\23\DatacenterCorp set do23=C:\windvd2\setup\23\DatacenterOEM set ec23=C:\windvd2\setup\23\EnterpriseCorp set eo23=C:\windvd2\setup\23\EnterpriseOEM set sc23=C:\windvd2\setup\23\ServerCorp set so23=C:\windvd2\setup\23\ServerOEM set wc23=C:\windvd2\setup\23\WebCorp set wo23=C:\windvd2\setup\23\WebOEM
:: Custom Windows Name :: Custom Windows Directory :: Use this if you have a custom windows installation, like "Windows XP Pro Corp for Classroom N-3107"
set cwinname= set cwinpath=skip
Here is the part that cleans up the files created by the main batch file. Code: [Select]IF EXIST STFU (DEL STFU) IF EXIST vars.bat (DEL vars.bat) Cheesh, 650 lines! I guess the KISS method doesn't work here.
Looking at your code, what I see are 19 variables floating around the environment, all logic is unconditional and my personal favorite, the unresolved variable waiting for a variable that has yet to be defined. What I don't see are conditional statements or any attempt to try and tie all these variables together.
How does the front-end of this unit run? Is the user presented with a menu to choose which distribution is to be updated, or does this unit simply run from top to bottom updating every distribution?
Having so many variables makes is hard (if not impossible) to write a generic batch file. It's the value of the variables that will drive vars.bat not the names.
If the front-end of this unit presents a menu, once the user's choice is captured, a series of if statements would set a series of variables. Each if statement would set up the same set of variables using different values of course. Instead of creating variables to hold values in order to set another variable, this would be the area to hard code the values that are needed to run vars.bat. It would also make your code more readable, by virtue of setting variables to values and not other variables.
Example: Code: [Select]echo 1. Windows 2000 Advanced echo 2. Windows 2000 DataCenter set /p opt=Enter CD to slipstream: if .opt==.1 ( set directory=somepath set cmdswitches=/s:somepath set p=somefile.exe ) if .opt==.2 set directory=someotherpath set cmdswitches=/s:someotherpath set p=somefile.exe ) . . rest of options go here . ) . . unconditional logic to create/execute vars.bat goes here .
Obviously if you find common code in all the if statements, you can move it outside the if sequence. Actually the set p=someprogram.exe is duplicated and can be moved outside the if sequence. The vars.bat can then use this common set of variables allowing you to write generic code and letting the processor resolve the variables.
On the other hand, if all the distributions get updated during a single run, you might consider a for loop to cycle thru all the CD's. The same logic for the variables applies, but the for command will drive the logic sequentially for all 19 distributions.
Example: Code: [Select]for /l %%x in (1,1,19) do ( if %%x==1 ( set directory=somepath set cmdswitches=/s:somepath set p=somefile.exe ) if %%x==2 set directory=someotherpath set cmdswitches=/s:someotherpath set p=somefile.exe ) . . rest of options go here . ) . . unconditional logic to create/execute vars.bat goes here .
Once you've written the logic for one option, the others should be easy and you'll notice a pattern developing. Unless you have some extreme bells and whistles in your file, I'm pretty sure you can cut down on those 650 lines.
Maybe this will give you some ideas. hehe most of the user interaction uses the getkey.com file to process the user's selection I'm going to say that it's roughly between 1/6 and 1/3 of it, between the echo lines and the IF statements that the MENUS require because of that method.
Here's my menu options: Code: [Select]ECHO 1) Windows 2000, XP, and Server 2003 ECHO 2) Windows XP and Server 2003 ECHO 3) Windows 2000 and XP ECHO 4) Windows 2000 and Server 2003 ECHO 5) Windows 2000 Only ECHO 6) Windows XP Only ECHO 7) Windows 2003 Only ECHO 8) Custom Windows Distro
And if a user selects any one of 5-7, they are prompted with the option to install all of them, or to pick a specific version of it (IE: XP Pro Corporate).
keep in mind that I am a noob and since my knowledge is so immensely limited, I may be going about this with a totally illogical, complex approach when simplicity is simply achieved through logic
I'll play around with the FOR command, but if I have any questions do you mind if I send you a PM or e-mail via the forum, maybe attach my code so you can check it out if you have time?
Thanks Overkill
|