Hi all,
I have used the following code in the past under Windows Xp without issue to run a series of configuration files based on the IP range. However, I get the above error message on Line 79 Char 7 (the Split command) under Windows 7 64-bit. I'm stumped, any ideas?
I have used the following code in the past under Windows Xp without issue to run a series of configuration files based on the IP range. However, I get the above error message on Line 79 Char 7 (the Split command) under Windows 7 64-bit. I'm stumped, any ideas?
Code:
Option Explicit
Dim IP_Address : IP_Address = GetIP()
IP_Address = ip2num(IP_Address)
If IP_Address = "0.0.0.0" OR IP_Address = "" Then
MsgBox "No IP Address found – Unable to configure."
Else
Dim WshNetwork
Dim objShell
Set WshNetwork = CreateObject("WScript.Network")
Set objShell = CreateObject("Wscript.Shell")
If IP_Address >= ip2num("10.100.10.1") _
And IP_Address <= ip2num("10.100.10.79") Then
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K C:\Scripts\Machine\d.bat"), 1, True
ElseIf IP_Address >= ip2num("10.100.10.80") _
And IP_Address <= ip2num("10.100.10.89") Then
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K C:\Scripts\Machine\baseConfig.bat"), 1, True
ElseIf IP_Address >= ip2num("10.100.10.90") _
And IP_Address <= ip2num("10.100.10.254") Then
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K C:\Scripts\Machine\d.bat"), 1, True
ElseIf IP_Address >= ip2num("10.100.20.1") _
And IP_Address <= ip2num("10.100.20.254") Then
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K C:\Scripts\Machine\h.bat"), 1, True
ElseIf IP_Address >= ip2num("10.100.30.1") _
And IP_Address <= ip2num("10.100.30.254") Then
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K C:\Scripts\Machine\sunset.bat"), 1, True
ElseIf IP_Address >= ip2num("10.100.40.1") _
And IP_Address <= ip2num("10.100.40.254") Then
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K C:\Scripts\Machine\b.bat"), 1, True
ElseIf IP_Address >= ip2num("10.100.60.1") _
And IP_Address <= ip2num("10.100.60.254") Then
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K C:\Scripts\Machine\t.bat"), 1, True
ElseIf IP_Address >= ip2num("10.100.70.1") _
And IP_Address <= ip2num("10.100.70.254") Then
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K C:\Scripts\s.bat"), 1, True
End If
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
Public Function ip2num(ip)
Dim i, a, N
a = Split(IP, ".")
N = CDbl(0)
For i = 0 To UBound(a)
N = N * 256 + a(i)
Next
ip2num = N
End Function
Comment