Home » Questions » Computers [ Ask a new question ]

Utility to change desktop background based on current IP address

Utility to change desktop background based on current IP address

I'd like to have a different desktop background depending on which network I'm attached to (home, work, roaming, etc.).

Asked by: Guest | Views: 62
Total answers/comments: 1
Guest [Entry]

"You could create a script that checks your IP address and then changes your background.

Too bad my scripting experience is so low, I would have no idea how to write this.

Here's a VBscript to find your IP Address:

'GetIPaddr.vbs - Check the IP address you are currently
'connected to the Internet with (or LAN IP).
'© Bill James - bill@billsway.com
' rev 15 Jan 2002
' Now works with Windows NT, 2K, XP

Option Explicit
Dim IP_Address : IP_Address = GetIP()

If IP_Address = ""0.0.0.0"" OR IP_Address = """" Then
MsgBox ""No IP Address found.""
Else
InputBox vbcrlf & ""Current IP Address is "" & IP_Address & _
vbcrlf & vbcrlf & vbcrlf & vbcrlf & _
""(Use Ctrl + C to copy IP Address to Clipboard)"", _
""GetIPaddr.vbs © Bill James"", IP_Address
End If

Function GetIP()
Dim ws : Set ws = CreateObject(""WScript.Shell"")
Dim fso : Set fso = CreateObject(""Scripting.FileSystemObject"")
Dim TmpFile : TmpFile = fso.GetSpecialFolder(2) & ""/ip.txt""
Dim ThisLine, IP
If ws.Environment(""SYSTEM"")(""OS"") = """" Then
ws.run ""winipcfg /batch "" & TmpFile, 0, True
Else
ws.run ""%comspec% /c ipconfig > "" & TmpFile, 0, True
End If
With fso.GetFile(TmpFile).OpenAsTextStream
Do While NOT .AtEndOfStream
ThisLine = .ReadLine
If InStr(ThisLine, ""Address"") <> 0 Then IP = Mid(ThisLine, InStr(ThisLine, "":"") + 2)
Loop
.Close
End With
'WinXP (NT? 2K?) leaves a carriage return at the end of line
If IP <> """" Then
If Asc(Right(IP, 1)) = 13 Then IP = Left(IP, Len(IP) - 1)
End If
GetIP = IP
fso.GetFile(TmpFile).Delete
Set fso = Nothing
Set ws = Nothing
End Function

Now I need a smart programmer to add something to make it change your background, when the IP has a certain range/value."