dhorowitz Posted July 22, 2010 Posted July 22, 2010 I'm trying to create a batch script to push out 2 MSI packages. I've got the install part of the script written, but the third character of our computer naming scheme indicates whether or not I want the install to proceed. Anyone know how to read the 3rd character of the %computername% variable?
PiqueABoo Posted July 22, 2010 Posted July 22, 2010 Checks if the third letter (2=you count from 0, 1 = length) is "7": set letter3=%computername:~2,1% if "%letter3%" equ "7" ( rem do all your installing in here )
dhorowitz Posted July 23, 2010 Author Posted July 23, 2010 This is what I have so far. It's still going through the install process when the if condition is not satisfied. set letter3=%computername:~2,1% if %letter3% equ "T" goto loadsoft echo PC not need update exit pause :loadsoft msiexec /i "\\uufsd\district\pushed\district\activinspire\driver.msi" /qn msiexec /i "\\uufsd\district\pushed\district\activinspire\activinspire.msi" /qn
srochford Posted July 23, 2010 Posted July 23, 2010 (edited) the "if" statement defaults to being case sensitive and you either don't need the quotes around the "T" or you need them around the variable as well and not sure about using "equ" - I use == if /i "%letter3%" == "T" goto loadsoft (the "" bit is essential if the variable might not be set; it can actually be anything, it's just to make sure that you don't end up with a blank on the left hand side of the test) Edited July 23, 2010 by srochford
dhorowitz Posted July 23, 2010 Author Posted July 23, 2010 I added the /i switch to the if statement and it is not skipping to the loadsoft section if the condition is met. I just tested on a PC where the condition is met, and it just ran through the beginning and it tells me that the PC doesn't get the update (which is just there for testing purposes).
srochford Posted July 23, 2010 Posted July 23, 2010 have you also changed the quotes - it won't work as you have it because what you're doing is testing if T is equal to "T" which it isn't! Just make a really simple test file: @echo off set letter3=%computername:~2,1% if "%letter3%" == "T" echo "going to install" - on a machine where you want it to work it should say "going to install"; other machines should do nothing.
dhorowitz Posted July 23, 2010 Author Posted July 23, 2010 I removed the quotation marks around the T and it worked the way I want it to.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now