怎樣用API:GetcomputerName。
Public Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

解决方案 »

  1.   

    Option ExplicitPrivate Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    Private Sub Form_Load()
        Dim strString As String
        'Create a buffer
        strString = String(255, Chr$(0))
        'Get the computer name
        GetComputerName strString, 255
        'remove the unnecessary chr$(0)'s
        strString = Left$(strString, InStr(1, strString, Chr$(0)))
        'Show the computer name
        MsgBox strString
    End Sub
      

  2.   

    Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    '取计算机名
    '##ModelId=3C3C32920026
    Private Function GetLogonComputerName() As String
        Dim nRet As Long
        Dim lpBuffer As String
        Dim nSize As Long
        
        'get computer name
        nSize = 60
        lpBuffer = String(nSize + 1, 0)
        nRet = GetComputerName(lpBuffer, nSize)
        lpBuffer = left(lpBuffer, nSize)
        
        GetLogonComputerName = lpBuffer
      
    End Function'try .....
      

  3.   

    Private Sub Form_Load()        
      TxtValue.text = WorkstationID()
    End Sub
    Public Function WorkstationID() As String
      Dim sBuffer As String * 255  If GetComputerNameA(sBuffer, 255&) > 0 Then
        WorkstationID = Left$(sBuffer, InStr(sBuffer, vbNullChar) - 1)
      Else
        WorkstationID = "?"
      End IfEnd Function