简体   繁体   中英

Simple batch script to check computer name in domain

Premise: I'm not a programmer.

I need to do a simple batch script that checks the computer name in domain and if it's the right name excute another batch script (I have already it) otherwise it check the next computer's name.

I trid to do something but it's very hard for me.

If %computername%=VDSXXXXXXD
   then c:\XXXXX\XXXX.bat
   echo VDSXXXXD FOUND
Else %computername%=VDSYYYYYD
     then c:\XXXXXX\ZZZ.bat
     echo VDYYYYYD FOUND
Else %computername%=VDSYYYYYD
     then c:\XXXXXX\ZZZZ.bat
     echo VDSZZZZZD FOUND
goto 
:End

You were quite close for a non-programmer, this should work for you (though having a text file with all computer names would be optimal.)

If "%computername%"=="VDSXXXXXXD" (
start c:\XXXXX\XXXX.bat
echo VDSXXXXD FOUND
goto :eof
)
if "%computername%"=="VDSYYYYYD" (
start c:\XXXXXX\ZZZ.bat
echo VDYYYYYD FOUND
goto :eof
)
if "%computername%"=="VDSYYYYYD" (
start c:\XXXXXX\ZZZZ.bat
echo VDSZZZZZD FOUND
goto :eof
) 

:eof
Exit

And that should work for you fine,

Mona

Here is a simple and straight forward way of doing it.

If there is a relationship between the name and batch file then a loop would be easier to maintain.

@echo off
If %computername%=VDSXXXXXXD (echo VDSXXXXD FOUND & c:\XXXXX\XXXD.bat)
If %computername%=VDSXXXXXXE (echo VDSXXXXE FOUND & c:\XXXXX\XXXE.bat)
If %computername%=VDSXXXXXXF (echo VDSXXXXF FOUND & c:\XXXXX\XXXF.bat)
If %computername%=VDSXXXXXXG (echo VDSXXXXG FOUND & c:\XXXXX\XXXG.bat)
If %computername%=VDSXXXXXXH (echo VDSXXXXH FOUND & c:\XXXXX\XXXH.bat)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM