Hi,
Thanks that worked a treat and I have integrated it into my script. Here is is:
' Constants for type of event log entry
const EVENTLOG_SUCCESS = 0
const EVENTLOG_ERROR = 1
const EVENTLOG_WARNING = 2
const EVENTLOG_INFORMATION = 4
const EVENTLOG_AUDIT_SUCCESS = 8
const EVENTLOG_AUDIT_FAILURE = 16
'Echo constants
const FailedConnect = "Failed to connect, check if device is on and functioning, or Contact TSS"
Set WSHNetwork = CreateObject("WScript.Network")
Set WshShell = WScript.CreateObject("WScript.Shell")
UserString = WSHNetwork.UserName
usertime = now
' test the function is_ip
ip_adresses = split(IPAddress)
for each ip_adress in ip_adresses
'test if valid
if is_ip(ip_adress) then
wscript.echo "'" & ip_adress & "' is valid IP-adress."
else
wscript.echo "Error: '" & ip_adress & "' is invalid IP-adress !"
end if
next
' now calling the subroutine
call Enterip
'write username, date & time and IP Address to eventlog
WshShell.LogEvent EVENTLOG_INFORMATION, "Username " & userstring &", " & "Date " & usertime & " logged on via Terminal Services and attempted to restart " & IPAddress
'==========================================================================
' The following function will test if a machine is reachable via a ping
' using WMI and the Win32_PingStatus
'==========================================================================
If Reachable(IPAddress) Then
call TelnetFunc
Else
reachable(IPAddress)
wscript.sleep 1000
reachable(IPAddress)
wscript.sleep 1000
reachable(IPAddress)
wscript.echo FailedConnect
'wscript.quit
End If
Function Reachable(strComputer)
' On Error Resume Next
Dim wmiQuery, objWMIService, objPing, objStatus
wmiQuery = "Select * From Win32_PingStatus Where " & _
"Address = '" & strComputer & "'"
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set objPing = objWMIService.ExecQuery(wmiQuery)
For Each objStatus in objPing
If IsNull(objStatus.StatusCode) Or objStatus.Statuscode<>0 Then
Reachable = False 'if computer is unreacable, return false
Else
Reachable = True 'if computer is reachable, return true
End If
Next
End Function
'============================================================================
' The function fires up telnet (or whatever) using the specified port #
'============================================================================
'change port for different signs\busses
Sub Telnetfunc
wshshell.run("telnet " & IPAddress & " 21")
end sub
'============================================================================
' The following procedure will validate the textbox input and act accordingly
'============================================================================
sub EnterIP
'textbox for entering value
IPAddress = inputbox( "Please Enter IP Address:", "Ping", "10.190.?.?" )
'if cancel is pressed
if IsNull(IPAddress) or ipaddress = "" then
wscript.quit
end if
if not is_ip (IPAddress) then
wscript.echo "This needs to be an IP address like 10.190.23.13"
call enterip
'else
'wscript.echo "This is IP-adress '" & IPAddress & "'"
end if
end sub
'===================================================================================
' Function to split and identify the format of the IP address entered into checkbox
'===================================================================================
function is_ip(ip_adress)
is_ip = True
' split string into list
ip_adress_lst = split(ip_adress,".")
' if number of IP adress parts is 4
if uBound(ip_adress_lst) = 3 then
' validate if every IP part is numeric
for each ip_part in ip_adress_lst
if not isNumeric(ip_part) then
is_ip = False
exit for
end if
next
else
' if number of IP adress parts is not 4
is_ip = False
end if
end function
James