VB6.0获取计算机名 用户名最简单的方法

来源:互联网 发布:软件测试培训靠谱不 编辑:程序博客网 时间:2024/05/22 17:20

大家在做项目的时候经常会用到这个 像什么学生信息管理系统啦 小弟在此汇总一下 供大家参考


最简单的方法:


结果显示在文本框中 其他同理



获取计算机名:
 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 LongPrivate Sub Form_Click()    Dim StrT As String * 255    GetComputerName StrT, 255    Print StrTEnd Sub

用API获取用户名:


Private Declare Function GetUserName Lib "advapi32.dll" _Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As LongPrivate Sub Form_Click()    Dim StrT As String * 255    GetUserName StrT, 255    Print StrTEnd Sub