Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
‘获得计算机的名字
Public Function GetServerName() As String
Dim s$
Dim dl&
Dim sz&
s$ = String$(MAX_COMPUTERNAME_LENGTH + 1, 0)
sz& = MAX_COMPUTERNAME_LENGTH + 1
dl& = GetComputerName(s$, sz)
GetServerName = Left(s$, sz)
End Function获得本机多个IP(网卡可能绑定多个IP) 我是传递到ComboBox框中,你也可以传递到数组中
我的程序都通过调试了。
Public Sub GetIP(cboList As ComboBox)
Set IPConfigSet = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select IPAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each IPConfig In IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i = LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress)
AddList IPConfig.IPAddress(i), cboList
Next
End If
Next
End Sub
Public Sub AddList(ByVal strIP As String, cboList As ComboBox)
Dim blnIn As Boolean
Dim intCount As Integer
blnIn = False
For intCount = 0 To cboList.ListCount - 1
If UCase(strIP) = UCase(cboList.List(intCount)) Then
blnIn = True
Exit For
End If
Next
If Not blnIn Then
cboList.AddItem strIP, cboList.ListCount
End If
End Sub
‘获得计算机的名字
Public Function GetServerName() As String
Dim s$
Dim dl&
Dim sz&
s$ = String$(MAX_COMPUTERNAME_LENGTH + 1, 0)
sz& = MAX_COMPUTERNAME_LENGTH + 1
dl& = GetComputerName(s$, sz)
GetServerName = Left(s$, sz)
End Function获得本机多个IP(网卡可能绑定多个IP) 我是传递到ComboBox框中,你也可以传递到数组中
我的程序都通过调试了。
Public Sub GetIP(cboList As ComboBox)
Set IPConfigSet = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select IPAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each IPConfig In IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i = LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress)
AddList IPConfig.IPAddress(i), cboList
Next
End If
Next
End Sub
Public Sub AddList(ByVal strIP As String, cboList As ComboBox)
Dim blnIn As Boolean
Dim intCount As Integer
blnIn = False
For intCount = 0 To cboList.ListCount - 1
If UCase(strIP) = UCase(cboList.List(intCount)) Then
blnIn = True
Exit For
End If
Next
If Not blnIn Then
cboList.AddItem strIP, cboList.ListCount
End If
End Sub
Public Const MAX_COMPUTERNAME_LENGTH As Long = 31
sz& = MAX_COMPUTERNAME_LENGTH + 1
dl& = GetComputerName(s$, sz)
中的 dl&是干什么的?怎么没有用到?
Public Const MAX_COMPUTERNAME_LENGTH As Long = 31
这是一个返回值
在这里可以不用还有你返回为空是这个字符传没有定义