Solved

How to Check if a Hostname exist BGINFO batch file

Posted on 2011-09-25
9
1,038 Views
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
           
         else
              excute the BGINFO
     
0
Comment
Question by:geedi4
  • 4
  • 3
  • 2
9 Comments
 
LVL 4

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.
0
 
LVL 22

Assisted Solution

by:Paka
Paka earned 400 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.
0
 

Author Comment

by:geedi4
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

thanks
0
 

Author Comment

by:geedi4
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
pause
goto Bginfoexe

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

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

0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
LVL 22

Expert Comment

by:Paka
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...
0
 
LVL 4

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.
0
 
LVL 4

Assisted Solution

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

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

0
 

Accepted Solution

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

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

Author Closing Comment

by:geedi4
ID: 36890352
i have tested  and it worked thanks everybody
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I'm a big fan of Windows' offline folder caching and have used it on my laptops for over a decade.  One thing I don't like about it, however, is how difficult Microsoft has made it for the cache to be moved out of the Windows folder.  Here's how to …
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup". After a while, you have entered a loop for Auto repair which does not fix anything and you will be in a  panic as all your work w…
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.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now