maidinhdan > 16-05-18, 09:18 PM
(15-05-18, 05:20 PM)thanhtruong Đã viết: Mình chỉ cần lấy tên máy thôi. hay là IP thì làm thế nào
Private Declare Function apiGetComputerName Lib "kernel32" _
Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function Laytenmaytinh() As String
'Returns the computername
Dim lngLen As Long, lngX As Long
Dim strCompName As String
lngLen = 16
strCompName = String$(lngLen, 0)
lngX = apiGetComputerName(strCompName, lngLen)
If lngX <> 0 Then
Laytenmaytinh = Left$(strCompName, lngLen)
Else
Laytenmaytinh = ""
End If
End Function
Function LayIP()
Dim objWMIService As Object
Dim colItems As Object
Dim itm As Object
Set objWMIService = GetObject("winmgmts:\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
For Each itm In colItems
LayIP = LayIP & itm.Properties_("IPAddress")(0) ' & vbCrLf
Next
End Function