Tag Archives: Server

How to automate BGInfo using batch files

If you are not familiar with BGInfo, do a quick search and see how it can help identify and provide valuable information to system administrators while working on desktops and servers.

I love to script, so I created a few simple batch command files that help automate the process of utilizing BGInfo for the servers I support.

So, here is the environment in which I work in so you can get a little bit of understanding as to the challenge I was presented with in implementing BGInfo across all of my Windows servers.

We have two data centers, ADC & BDC. The majority of our servers follow a naming convention that have the first three letters identify which data center they reside in.

The fourth letter in the server name identifies the type of server…
(P)roduction, (D)evelopment, (Q)uality Assurance, (T)est, (S)tage

Then, I have a certain number of servers that were built prior to the naming standard and don’t comply, so I had to add some special name checking to work these into my automation.

I have three different sets of batch files that do different things, so I’ll show all three and explain what is happening in each one.

First one is the main batch file that is initiated by creating a shortcut to it and placing it in the common startup folder of every server. We use a product called BCM to place the shortcut, but there are other methods to automate this as well.

serverbackground.bat

rem turns off activity in command prompt interface
@echo off
rem makes check variable = to the 4th character in computername
set check=%computername:~3,1%
rem makes srv variable = 2nd and 3rd characters in computername
set srv=%computername:~1,2%
rem this is to remove any previous BGInfo setting placed by previous users
if exist “C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\*.bgi” (
del “C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\*.bgi” /q
)
rem if srv doesn’t =DC, then check to see if a batch file already exists. If batch file exists, run batch file to update background info for current user, then exit.
if not %srv% == DC (
if exist C:\server\bg.bat (
call C:\server\bg.bat
exit
)
rem this action is initiated if srv doesn’t = DC, so this is a non compliant server name
call \\adcpserver01\BGInfo\\ask.bat
)
rem these check to see if the variable check are one of the identified servers, if so, it will initiate the appropriate identifying profile. The path is shared to the location of the BGInfo application and supporting files.
if %check%==P call \\adcpserver01\BGInfo\\BGInfo64.exe \\adcpserver01\BGInfo\prod.bgi /timer:0 /silent /accepteula
if %check%==D call \\adcpserver01\BGInfo\\BGInfo64.exe \\adcpserver01\BGInfo\dev.bgi /timer:0 /silent /accepteula
if %check%==Q call \\adcpserver01\BGInfo\\BGInfo64.exe \\adcpserver01\BGInfo\qa.bgi /timer:0 /silent /accepteula
if %check%==T call \\adcpserver01\BGInfo\\BGInfo64.exe \\adcpserver01\BGInfo\test.bgi /timer:0 /silent /accepteula
if %check%==S call \\adcpserver01\BGInfo\\BGInfo64.exe \\adcpserver01\BGInfo\stage.bgi /timer:0 /silent /accepteula

ask.bat

rem turns off activity in command prompt interface
@echo off
rem allows input, asking for type of server
set /p check=What type of server is this? (P)roduction, (D)evelopment, (Q)uality Control, (T)est, (S)tage:
rem if check variable = P, initiate production profile and copy production batch file to c:\server\ for continual use and rename for universal execution from any user.
if /i %check%==P (
call \\adcpserver01\BGInfo\\BGInfo64.exe \\adcpserver01\BGInfo\prod.bgi /timer:0 /silent /accepteula
xcopy \\adcpserver01\BGInfo\bgprod.bat “C:\server\” /y
rename c:\server\bgprod.bat bg.bat
)
if /i %check%==D (
call \\adcpserver01\BGInfo\\BGInfo64.exe \\adcpserver01\BGInfo\dev.bgi /timer:0 /silent /accepteula
xcopy \\adcpserver01\BGInfo\bgdev.bat “C:\server\” /y
rename c:\server\bgdev.bat bg.bat
)
if /i %check%==Q (
call \\adcpserver01\BGInfo\\BGInfo64.exe \\adcpserver01\BGInfo\qa.bgi /timer:0 /silent /accepteula
xcopy \\adcpserver01\BGInfo\bgqa.bat “C:\server\” /y
rename c:\server\bgqa.bat bg.bat
)
if /i %check%==T (
call \\adcpserver01\BGInfo\\BGInfo64.exe \\adcpserver01\BGInfo\test.bgi /timer:0 /silent /accepteula
xcopy \\adcpserver01\BGInfo\bgtest.bat “C:\server\” /y
rename c:\server\bgtest.bat bg.bat
)
if /i %check%==S (
call \\adcpserver01\BGInfo\\BGInfo64.exe \\adcpserver01\BGInfo\stage.bgi /timer:0 /silent /accepteula
xcopy \\adcpserver01\BGInfo\bgstage.bat “C:\server\” /y
rename c:\server\bgstage.bat bg.bat
)

bgprod.bat

rem turns off activity in command prompt interface
@echo off
rem executes the prod profile
call \\adcpserver01\BGInfo\\BGInfo64.exe \\adcpserver01\BGInfo\prod.bgi /timer:0 /silent /accepteula