📄 main.frm
字号:
VERSION 5.00
Begin VB.Form Main
Caption = "Form1"
ClientHeight = 3345
ClientLeft = 60
ClientTop = 345
ClientWidth = 4905
LinkTopic = "Form1"
ScaleHeight = 3345
ScaleWidth = 4905
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "设置计算机名称"
Height = 375
Left = 480
TabIndex = 3
Top = 1080
Width = 1695
End
Begin VB.TextBox Text2
Height = 375
Left = 2280
TabIndex = 2
Text = "Text1"
Top = 1080
Width = 2175
End
Begin VB.CommandButton Command1
Caption = "获取计算机名称"
Height = 375
Left = 480
TabIndex = 1
Top = 480
Width = 1695
End
Begin VB.TextBox Text1
Height = 375
Left = 2280
TabIndex = 0
Text = "Text1"
Top = 480
Width = 2175
End
End
Attribute VB_Name = "Main"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
' 获取计算机名称的API
Private Declare Function GetComputerName Lib "kernel32" _
Alias "GetComputerNameA" (ByVal lpBuffer As _
String, nSize As Long) As Long
' 获取计算机名称的API
Private Declare Function SetComputerName Lib "kernel32" _
Alias "SetComputerNameA" (ByVal lpComputerName _
As String) As Long
Private Sub Command1_Click()
Dim Name As String, Length As Long
Length = 255
Name = String(Length, 0)
' 获取名称
GetComputerName Name, Length
Name = Left(Name, Length)
Text1.Text = Name
End Sub
Private Sub Command2_Click()
Dim Name As String
Name = Text2.Text
SetComputerName Name
MsgBox "改变了电脑名称,必须等到下次关机才生效!"
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -