标题:单位的电脑上网时是加域的,请问,如何判断电脑已经拔掉网线,或不在域中? ...
只看楼主
mansohu
Rank: 1
等 级:新手上路
帖 子:190
专家分:0
注 册:2013-3-20
结帖率:21.05%
已结贴  问题点数:10 回复次数:1 
单位的电脑上网时是加域的,请问,如何判断电脑已经拔掉网线,或不在域中?谢谢!
单位的电脑上网时是加域的,请问,如何判断电脑已经拔掉网线,或不在域中?谢谢!
搜索更多相关主题的帖子: 如何 网线 
2016-04-20 16:50
HVB6
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:15
帖 子:320
专家分:561
注 册:2013-10-30
得分:10 
判断是否可以访问网络(互联网 局域网)
方法一: API方式
Private Declare Function InternetGetConnectedState Lib "wininet.dll" _
(lpdwFlags As Long, ByVal dwReserved As Long) As Long '申明API
Sub net()
    Dim netweb As Long
    If InternetGetConnectedState(netweb, 0) <> 0 Then
       MsgBox "可以"
    Else
       MsgBox "不可以"
    End If
End Sub
方法二:XMLHTTP
Sub net()
Dim xml6 As Object
Set xml6 = CreateObject("Microsoft.XMLHTTP")
URL = "http://chiensq.blog.
xml6.Open "GET", URL, False
On Error Resume Next
xml6.Send
  If xml6.Status = 200 Then
    MsgBox "可以"
  Else
    MsgBox "不可以"
  End If
End Sub
方法三:ping
Public Function Pings(strMachines As String) As Boolean
aMachines = Split(strMachines, ";")
For Each machine In aMachines     Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select *
_
    from Win32_PingStatus where address = '" & machine & "'")
    For Each objStatus In objPing
        If IsNull(objStatus.StatusCode) Or objStatus.StatusCode <> 0 Then
            Debug.Print ("machine " & machine & " is not reachable")
            Pings = False
        Else
            Pings = True
        End If
    Next
Next
End Function


方法四:shell
Sub Chksys()
Dim  oExec
oExec = CreateObject("Wscript.shell").Run("ping chiensq.blog. -n 1", 0, True)
  If oExec = 0 Then
    msgbox "可以"
  Else
    msgbox"不可以"
  End If
End Sub
方法五:局域网
Sub net()
Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    If fso.FileExists("\\172.20.31.32\123\ver.txt") Then '文件夹FSO.folderexists(“\\172.20.31.32\123”)
        MsgBox "存在"
    Else
        MsgBox "不存在"
    End If
    Set fso = Nothing
End Sub
\172.20.31.32\123\ver.txt
是指一台ip为172.20.31.32的局域网计算机,的共享文件夹为123中的ver.txt文件
2016-04-20 20:11



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-463894-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.997316 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved