Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


How to Check if a Hostname exist BGINFO batch file

Posted on 2011-09-25
Medium Priority
Last Modified: 2013-12-23
i would like to check Hostnames before i depoly  BGINFO to my network. if exist  exit the script. the reason behind this is  i want to exclude some computers running BGinfo.  i  don't want to create  new OU AD to apply GPO.
i need a batch file to do that job. please help
   batch file it would look like
          If hostname = "hostA" :exit
              excute the BGINFO
Question by:geedi4
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2

Expert Comment

by:Ryan Weaver
ID: 36596546
The environment will give you %COMPUTERNAME% and %USERDNSNAME%, so you could:

if /i %COMPUTERNAME$ == "HostA" exit (or use a goto label if more needs to be done in the batch).

The /i would mean ignore case.
LVL 22

Assisted Solution

Paka earned 1600 total points
ID: 36596582
Copy to checkbginfo.bat
echo off
for /f "tokens=*" %%G in (testcomps.txt) do if %%G == %computername% (call CALLBGINFO.BAT)

Where testcomps.txt contains a list of computers you want to run BGINFO on.  Make sure you use UPPERCASE characters to define these.

And CALLBGINFO.BAT is another batch file to call BGINFO with the command line parameters - you probably want to display BGInfo immediately instead of waiting for the timeout.

Author Comment

ID: 36596590
thanks for quick reply

we have 100 computers how can i call and check txt file all the computers name in it.

or this script will do the job of 100 computers  /i %COMPUTERNAME$ == "HostA" exit

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 36596610
paka thanks mate

echo off
for /f "tokens=*" %%G in (testcomps.txt) do if %%G == %computername%
(call CALLBGINFO.BAT) do have to use the brackets

testcomps.txt  you mean all the computernames should be uppercase in txt file

my bginfo look like this do i have to change anything

@echo on

del "C:\Documents and Settings\guled\Local Settings\Temp\BGinfo.bmp" /F /Q
echo deleted image
goto Bginfoexe

echo create directory
mkdir C:\WINDOWS\Temp
cacls C:\WINDOWS\Temp /E /G  "Authenticated Users":F
goto Bginfoexe

if NOT exist C:\WINDOWS\Temp goto bgcreate
echo bg create
start C:\bginfo\bgibmp\bginfo.exe C:\bginfo\bgibmp\bginfo.bgi /silent /nolicprompt /timer:0
echo done

LVL 22

Expert Comment

ID: 36596620
Add all 100 computernames to the testcomps.txt file (make sure they are in capital letters) and the batch will read though the file and run BGInfo for those that are in the file.  Obviously, there will be a performance penalty if the the list gets too big, but for 100-200 the hit shouldn't be noticeable.

The for /f statement will take care of loading the names, the if %%G will check the names...

Expert Comment

by:Ryan Weaver
ID: 36596624
You could have a names.txt of to be excluded then you could do something like:

find %COMPUTERNAME% c:\file.txt > NULL
if ERRORLEVEL 1 exit

I believe this will work, but should definitely tested.

Assisted Solution

by:Ryan Weaver
Ryan Weaver earned 400 total points
ID: 36596633
Might need quotes around the variable.

find "%COMPUTERNAME%" c:\file.txt > NULL


Accepted Solution

geedi4 earned 0 total points
ID: 36596652
thanks fryguy nad paka.

i'm going to tested i will let you guys know.

Author Closing Comment

ID: 36890352
i have tested  and it worked thanks everybody

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
By default the complete memory dump option is disabled in windows . If we want to enable the complete memory dump for a diagnostic purpose, we have a solution for it. here we are using the registry method to enable this.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
This Micro Tutorial will go in depth within Systems and Security in Windows 7 and will go into detail regarding Action Center, Windows Firewall, System, etc. This will be demonstrated using Windows 7 operating system.

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question