Jump to content

Recommended Posts

Posted
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?
Posted

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

)

Posted

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

Posted (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 by srochford
Posted
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).
Posted

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.

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



×
×
  • Create New...