作成 2010.01.05
更新 2014.01.12
VBscript でコンピュータ名を取得する
WScript.Network を使用して取得
Option Explicit
Dim WshNetwork, myComputerName

Set WshNetwork = CreateObject("WScript.Network")
myComputerName = WshNetwork.ComputerName
WScript.Echo myComputerName
環境変数を使用して取得
Option Explicit
Dim WshShell, myComputerName

Set WshShell = CreateObject("WScript.Shell")
myComputerName = WshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
WScript.Echo myComputerName
WMIを使用して取得
Option Explicit

WScript.Echo myGetComputerName()
WScript.Quit

Function myGetComputerName()
  Dim wmiLocator
  Dim wmiService
  Dim pcInstance
  Dim pcEnumerator
  Dim outList

  Set wmiLocator = CreateObject("WbemScripting.SWbemLocator")
  Set wmiService = wmiLocator.ConnectServer
  Set pcInstance = wmiService.ExecQuery ("Select * From Win32_ComputerSystem")

  For Each pcEnumerator In pcInstance
    outList = pcEnumerator.Name
  Next

  myGetComputerName = outList
End Function
タグ: VBScript WMI

©2004-2017 UPKEN IPv4