find 'something' from the %computername% and act on it

Microsoft Windows
Post Reply
User avatar
MigrationUser
Posts: 336
Joined: 2021-Jul-12, 1:37 pm
Contact:

find 'something' from the %computername% and act on it

Post by MigrationUser »

04 May 2011 12:13
hilgie


Hi,

If the %computername% contains -a I want to set some variables. I want ot do this without writing the %computername% to a file and then use the findstr command (this is what I do now).

Anybody any idea?

Cheers,

Danny

P.S.

This is what I do now:

Code: Select all

set tempfile1=%~dp0\tempfile.lis
echo %computername% >%tempfile1%
findstr /i /c:-a %tempfile1% >NUL
if /i %errorlevel%==0 set snmphost1=snmp1.acc & set snmphost2=snmp2.acc
if /i not %errorlevel%==0 set snmphost1=snmp1.prd & set snmphost2=snmp2.prd
----------------------------

#2 04 May 2011 13:02
RG


This should do it:

Code: Select all

echo.%computername% | find "-a"
if errorlevel 1 (
   set snmphost1=snmp1.prd
   set snmphost2=snmp2.prd
   ) else (
  set snmphost1=snmp1.acc
  set snmphost2=snmp2.acc
)
you may want to use 'find /i' if you want the search to be case insensitive.

Last edited by RG (04 May 2011 13:04)

Windows Shell Scripting and InstallShield

----------------------------

#3 05 May 2011 09:32
hilgie


Great!

This does the job. Tnx!

Cheers,

Danny

----------------------------

#4 17 Jul 2011 07:46
flabdablet


I'd just test %COMPUTERNAME% directly, without involving findstr at all:

Code: Select all

if /i "%COMPUTERNAME:-a=%" neq "%COMPUTERNAME%" (
    echo Contains -a
) else (
    echo Doesn't contain -a
)
Post Reply