确定远程PC是否在线的最快方法 [英] Quickest way to determine if a remote PC is online

查看:120
本文介绍了确定远程PC是否在线的最快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我倾向于在远程PC上运行许多命令,但是我总是检查以确保它们首先在线.我目前使用此代码:

I tend to run a lot of commands against remote PCs, but I always check to make sure they are online first. I currently use this code:

If objFSO.FolderExists("\\" & strHost & "\c$") Then
    'The PC is online so do your thing

但是,当远程PC不在线时,我的笔记本电脑需要大约45秒钟才能超时并解析为FALSE.

However, when the remote PC is not online, it takes my laptop ~45 seconds before it times out and resolves to FALSE.

是否有加速超时的方法?还是有另一种易于实施的解决方案来确定PC是否在线?

Is there a way to hasten the timeout? Or is there another easily implementable solution to determine if a PC is online?

推荐答案

您可以使用WMI对其执行ping操作.

You could use WMI to ping it.

Function IsOnline(strHost As String) As Boolean

    Dim strQuery As String
    strQuery = "select * from Win32_PingStatus where Address = '" & strHost & "'"

    Dim colItems As Object
    Set colItems = GetObject("winmgmts://./root/cimv2").ExecQuery(strQuery)

    Dim objItem As Object
    For Each objItem In colItems
        If IsObject(objItem) Then
            If objItem.StatusCode = 0 Then
                IsOnline = True
                Exit Function
            End If
        End If
    Next

End Function

这篇关于确定远程PC是否在线的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆