Environ("computername")
2.WScript Shell Object
CreateObject("WScript.Shell").ExpandEnvironmentStrings("%COMPUTERNAME%")
3.WScript Network Object
CreateObject("WScript.Network").ComputerName
4.API方法
#If VBA7 And Win64 Then
'x64 Declarations
Declare PtrSafe Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As LongPtr) As LongPtr
#Else
'x32 Declaration
Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
#End If
Function ComputerName() As String
Dim sBuff As String * 255
Dim lBuffLen As Long
Dim lResult As Long
lBuffLen = 255
lResult = GetComputerName(sBuff, lBuffLen)
If lBuffLen > 0 Then
ComputerName = Left(sBuff, lBuffLen)
End If
End Function
附 件:
Access软件网QQ交流群(群号:39785885)
Access源码网店