Ping remote host in Javascript using WMI
I’ve been working on a simple Windows Sidebar Gadget that will determine if a remote host is online or not. For the connectivity test I chose ping, since it’s lightweight and unlikely to disturb any services on a device.
Ping using WMI
function Ping(host) { var wmi = GetObject("Winmgmts:"); var eStatus = new Enumerator(wmi.ExecQuery( "Select StatusCode from Win32_PingStatus Where Address='" + host + "'")); return eStatus.item().StatusCode == 0; }
The function Ping will return true if the host is online, false otherwise. Optionally, a Timeout parameter may be specified in the WMI query.
