怎样取得本计算机名称?

解决方案 »

  1.   

    Private Declare Function GetComputerName Lib "kernel32" Alias _
        "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    Private Declare Function SetComputerName Lib "kernel32" Alias _
        "SetComputerNameA" (ByVal lpComputerName As String) As Long
        Private Sub Command1_Click()
        Dim Name1 As String * 255
        Dim name As String
        Dim i As Integer
        
        i = GetComputerName(Name1, 255)
        
        If i <> 0 Then
            name = Name1
        Else
            name = "unknown"
        End If
        
        Text1 = name
     end sub
      

  2.   

    Option ExplicitPrivate Declare Function SetComputerName Lib "kernel32" Alias _
        "SetComputerNameA" (ByVal lpComputerName As String) As Long
    Private Declare Function GetComputerName Lib "kernel32" Alias _
        "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As LongPrivate Sub Command1_Click()
        Dim Name1 As String * 255
        Dim name As String
        Dim i As Integer
        
        i = GetComputerName(Name1, 255)
        
        If i <> 0 Then
            name = Name1
        Else
            name = "unknown"
        End If
        
        Text1 = name
     End SubPrivate Sub Command2_Click()
    Dim i As Integer
    i = SetComputerName("husthiiiiii")
    Debug.Print i
    End Sub
    显示i=1,说明更改名称成功,但是再按command1,发现名字依然不变,请问为什么?