戻る



コンピュータ名を取得する方法
動作環境 Windows98/2000 開発環境 Visual Basic 6.0 (+SP5)
説明 WshNetwork オブジェクトの ComputerName プロパティを利用して、コンピュータ名を取得します。
用意するもの:標準フォーム(Form1)、コマンドボタン (Command1)


Private Sub Command1_Click()

Dim MyWSNet As Object
Dim MyPCName As String

Set MyWSNet = CreateObject("WScript.Network")

MyPCName = MyWSNet.ComputerName

MsgBox MyPCName, vbInformation, "コンピュータ名を取得"

Set MyWSNet = Nothing

End Sub