标签:
‘ 声明GetComputerName
Private Declare Function GetComputerName Lib
"kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As
Long
‘ 声明SetComputerName
Private Declare Function SetComputerName Lib
"kernel32" Alias "SetComputerNameA" (ByVal lpComputerName As String) As
Long
‘定义一个获取计算机名字的函数
Private Function GetCName(ByRef CName) As
Boolean
Dim sCName As String ‘ 计算机的名字
Dim lComputerNameLen As Long
‘ 计算机名字的长度
Dim lResult As Long ‘ GetComputerName的返回值
Dim RV As
Boolean ‘ GetCName返回值,若为TRUE则表示操作成功
lComputerNameLen = 256
sCName
= Space(lComputerNameLen)
lResult = GetComputerName(sCName,
lComputerNameLen)
If lResult <> 0 Then
CName =
Left$(sCName, lComputerNameLen)
RV = True
Else
RV =
False
End If
GetCName = RV
End Function
‘
定义一个修改计算机名字的函数
Private Function SetCName(ByVal CName As String) As
Boolean
Dim lResult As Long
Dim RV As Boolean
lResult =
SetComputerName(CName)
If lResult <> 0 Then
RV = True ‘
修改成功
Else
RV = False
End If
SetCName = RV
End
Function
标签:
原文地址:http://www.cnblogs.com/lbnnbs/p/4784919.html