carlmfischer.com BGInfo configuration

I am a big fan of BGInfo for my Windows laptops. The only problem I had with BGInfo had to do with the wired and wireless network adapters, BGInfo would display a space for both entries, even when one was not used. Either it would display 0.0.0.0 or (none).
bginfo

After looking around, I combined a few vbscripts, utilized a few batch scripts, and I have what I believe is to be a nice layout of displaying the IP Address; DNS Server; and DHCP Server for the active network connection, whether it is wired or wireless.

The vbscript runs three batch files to obtain the ip, dns and dhcp server.

Windows 7

This was originally written for WindowsXP, but since I finally upgraded to Windows7 and I had to make some modifications:

I changed the path from where bginfo resided from C:\Program Files\bginfo to C:\bginfo (I ran into permission issues).
I changed where bginfo stored the the bmp to the users temp directory (also permission issues).
I changed from using a startup batch file stored in the start menu's startup folder to editing the Group Policy and under Computer Configuration|Admin Templates|System|Logon. I now run the batch file (bg.bat) from the Run these programs at user logon.
I also changed the vbscript to include a sleep command to let the wireless network authenticate and get the ip addrress. WScript.sleep 20000 Previously I would let the startup batch file sleep, but for some reason the batch file was closing before finishing the vbs script.

Batch Files

This is the layout of the bg_ip batch file: setlocal
for /f "delims=: tokens=1-2" %%c in ('ipconfig /all ^| find "IP"') do set GetIP=%%d
endlocal & set GetIP=%GetIP:~1%
echo %GetIP% > "C:\bginfo\ip.txt"
The batch file writes the current ip address to ip.txt, but with a carriage return at the end, which I'll correct later in the vbscript.
The bg_dns and bg_dhcp batch files are similar to the above, except they write out the respective values for the dns and dhcp server.

VBScript

The vbscript calls the three different batch files to write the values of the ip, dns and dhcp server to three different files, all located in C:\bginfo\.
Then the vbscript reads the three text files, removes the carriage return at the end of each value (so bginfo will not display an unnecessary space), and re-writes the values to the same files.
Now the ip, dns and dhcp has the raw value of the respective IP, and gives BGInfo the necessary values to display.

Here is the vbscript: Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Const ForWriting = 2

'define the batch files
sBatFile = "c:\bginfo\bg_ip.bat"
sBatFile2 = "c:\bginfo\bg_dns.bat"
sBatFile3 = "c:\bginfo\bg_dhcp.bat"

' spaces in the path
sBatFileShort = oFSO.GetFile(sBatFile).ShortPath
sBatFile2Short = oFSO.GetFile(sBatFile2).ShortPath
sBatFile3Short = oFSO.GetFile(sBatFile3).ShortPath

'new for windows7
WScript.sleep 20000

' Run the batch file hidden, and let the VBScript wait for the batch file to finish
oShell.Run sBatFileShort, 0, True
oShell.Run sBatFile2Short, 0, True
oShell.Run sBatFile3Short, 0, True

'set ip
Set objFile = objFSO.OpenTextFile("c:\bginfo\ip.txt", ForReading)
strFile = objFile.ReadAll
objFile.Close

intLength = Len(strFile)
strEnd = Right(strFile, 2)

If strEnd = vbCrLf Then
strFile = Left(strFile, intLength - 2)
Set objFile = objFSO.OpenTextFile("c:\bginfo\ip.txt", ForWriting)
objFile.Write strFile
objFile.Close
End If

'set dns
Set objFile = objFSO.OpenTextFile("c:\bginfo\dns.txt", ForReading)
strFile = objFile.ReadAll
objFile.Close

intLength = Len(strFile)
strEnd = Right(strFile, 2)

If strEnd = vbCrLf Then
strFile = Left(strFile, intLength - 2)
Set objFile = objFSO.OpenTextFile("c:\bginfo\dns.txt", ForWriting)
objFile.Write strFile
objFile.Close
End If

'set dhcp
Set objFile = objFSO.OpenTextFile("c:\bginfo\dhcp.txt", ForReading)
strFile = objFile.ReadAll
objFile.Close

intLength = Len(strFile)
strEnd = Right(strFile, 2)

If strEnd = vbCrLf Then
strFile = Left(strFile, intLength - 2)
Set objFile = objFSO.OpenTextFile("c:\bginfo\dhcp.txt", ForWriting)
objFile.Write strFile
objFile.Close
End If

Startup Batch File

I use another batch file at startup to then run bginfo, and obtain the values for display. The batch file sleeps for 5 seconds to give the laptop a chance to authenticate with Radius and obtain the ip from the dhcp server before running the script.
@ECHO OFF
rem sleep for 5 seconds:
rem sleeping done in vbs script
rem ping 1.0.0.0 -n 1 -w 5000 >NUL
"c:\bginfo\bg_network.vbs"
"c:\bginfo\Bginfo.exe" /timer:0 /I:"c:\bginfo\bg_config.bgi"

Configure BGInfo

Once this was done, I configured BGInfo to use three custom fields, reading the respective .txt files from the result of the vbscript.

Summary

This gives me a clean looking display, whether I am using wireless or not:
bginfo
I am by no means a vbscript expert, but this seems to work for my Thinkpad, and my Macbook while using bootcamp to boot Windows.