【实例说明】 通过Windows网上邻居可以修改计算机名。本例将介绍通过VB编程来修改计算机的名称。运行程序,输入新的计算机名,然后单击“确定”按钮,即可修改计算机名。
【编程思路】 本例调用API函数中的SetComputerName函数,SetComputerName函数用来设置计算机的名称。下面是相关的函数声明及参数:
函数声明:
Private Declare Function SetComputerName Lib "kernel32" _
Alias "SetComputerNameA" _
(ByVal lpComputerName As String) As Long
参数:lpComputerName参数,指定要设置的计算机的新名字。
【设计步骤】
1.新建一个标准工程,创建一个新窗体,默认名为Form1。
2.在窗体上放置一个Text控件和两个CommandButton控件。
3.源程序 [素材源程序下载]
'API函数声明
Private Declare Function SetComputerName Lib "kernel32" _
Alias "SetComputerNameA" _
(ByVal lpComputerName As String) As Long
'确定按钮
Private Sub Command1_Click()
Dim myName As Long
myName = SetComputerName(Text1.Text)
MsgBox "修改成功,你的计算机名为:" & Text1.Text, vbInformation, "提示信息"
End Sub
'退出
Private Sub Command2_Click()
Unload Me
End Sub
|