'****************************************************** API函数
Declare Function GetComputerNameA Lib "kernel32" _
(ByVal strBuffer As String, lngSize As Long) As Long
'****************************************************** 获取机器名
Public Function fGetComputerName() As String
Dim lngReturn As Long
Dim lngBufferSize As Long
Dim strBuffer As String
lngBufferSize = 254
strBuffer = String(lngBufferSize, vbNullChar)
lngReturn = GetComputerNameA(strBuffer, lngBufferSize)
If CBool(lngReturn) Then
fGetComputerName = Left(strBuffer, lngBufferSize)
End If
End Function
我的方法:
1)
private sub form_load()
dim x as new winsock
textbox1.value = x.localHostName
textbox2.value = x.localIP
end sub
注:winsock类 %systemroot%\system32\mswinsck.ocx
2 )
private sub form_load
dim x as new adodb.recordset
set x = currentproject.connection.execute("SELECT HOST_NAME()")
textbox1.value = x(0)
end sub
注:SQL服务器。[em05]