Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

解决方案 »

  1.   

    Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    Public Function GetComputer() As String
            Dim strCompName As String
            Dim intHandle As Integer        strCompName = String(256, " ")
            intHandle = GetComputerName(strCompName, 256)
            strCompName = Left(strCompName, InStr(1, strCompName, Chr(0)) - 1)
            GetComputer = Trim(strCompName)
        End Function
      

  2.   

    Dim Name As String, Length As Long
        Length = 225
        Name = String(Length, Chr(0))
        GetComputerName Name, Length
        Name = Left(Name, Length)