Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

nt cmd script syntax

Status
Not open for further replies.

swabs

IS-IT--Management
Jul 28, 2003
155
US
hey all,
I want to match the computer name in a .bat file that with a variable. This is for mapping a printer based onto which machine a person is logging on to.

I know that the state below works:
IF %COMPUTERNAME% == LAB115
REM this will match only LAB115
REEM but I want to match LAB*

If %COMPUTERNAME begins with LAB* I want it to match. I know how to match this in perl, but I am lost in cmd script.

Any help would be greatly appreciated.
thanks,
Ben
 
If the digits after LAB are always numeric... you could echo your computername to a file, then do a:

for /f "tokens=1 delims=0123456789" %%l in (c:\temp\computer.txt) do set printer=%%l

This should strip off the all the initial alphabetic letters and store them as %printer%.

Good luck!
Debi
 
Thanks DebiJo,
I found this alternative to match a certain number of characters in %computername% and it works great.

If “%computername:~0,6%”==”Peylab” do



That takes the first 6 characters of the computername (starting at character 0) and tests to see if they are Peylab. But remember that this is case sensitive. So if the command ‘echo %computername%’ returns PEYLABxxxxx then you need to make the command:



If “%computername:~0,6%”==”PEYLAB” do
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top