大家在做项目的时候经常会用到这个 像什么学生信息管理系统啦 小弟在此汇总一下 供大家参考
最简单的方法:
结果显示在文本框中 其他同理
获取计算机名:
Text1.text = VBA.Environ("computername")
获取用户名:
text1.text=VBA.Environ("username")
用API取计算机名:
Private Declare Function GetComputerName Lib "kernel32" _
Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Sub Form_Click()
Dim StrT As String * 255
GetComputerName StrT, 255
Print StrT
End Sub
用API获取用户名:
Private Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Sub Form_Click()
Dim StrT As String * 255
GetUserName StrT, 255
Print StrT
End Sub