マシン情報の一覧を取得する

問題

簡単にマシン情報の取得をしたい。

解決

WSHからWMIを利用して情報の取得をする。

作業

Windowsからの情報取得方法
  • CIM Studioを使用して、欲しい情報を探す。

1. 検索ボックスから適当に探してみる。networkとか、osとか
2. 探索結果のクラスを開き、右上の[Instance]ボタンをクリックして自分の環境のデータを見る
http://dl.dropbox.com/u/461314/cim_studio_Image%202012-02-12-000.jpg

1. CIM Studioで探したクラスと複数の属性を選択し、コード生成をする。
http://dl.dropbox.com/u/461314/code_creator_Image%202012-02-12-000.jpg

※複数属性は、Ctrlキーを押しながらクリックする

VBScriptスクリプト

とりあえず版。
出力結果の見やすさと、Install済みソフトウェアを後で追加する。

strComputer = "." 
Dim model
Dim NumOfLogicalCPU
Dim NumOfPhysicalCPU
Dim TotalMem

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_ComputerSystem",,48) 
For Each objItem in colItems 
 model            = objItem.Model
 NumOfLogicalCPU  = objItem.NumberOfLogicalProcessors
 NumOfPhysicalCPU = objItem.NumberOfProcessors
 TotalMem         = objItem.TotalPhysicalMemory
Next

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_Processor",,48) 
For Each objItem in colItems 
 Wscript.Echo "---------------------------------------------------------"
 Wscript.Echo "CPU Information" 
 Wscript.Echo "---------------------------------------------------------"
 Wscript.Echo "Type                      : " & objItem.Description
 Wscript.Echo "Name                      : " & objItem.Name
 Wscript.Echo "Manufacturer              : " & objItem.Manufacturer
 Wscript.Echo "NumberOfProcessors        : " & NumOfPhysicalCPU
 Wscript.Echo "NumberOfLogicalProcessors : " & NumOfLogicalCPU
 Wscript.Echo "Current Clock Speed       : " & objItem.CurrentClockSpeed
 Wscript.Echo "Max Clock Speed           : " & objItem.MaxClockSpeed
 Wscript.Echo "L2 Cache Size             : " & objItem.L2CacheSize & vbCrLf
Next

Wscript.Echo "---------------------------------------------------------"
Wscript.Echo "Memory Information" 
Wscript.Echo "---------------------------------------------------------"
Wscript.Echo "Total Memory : " & TotalMem & vbCrLf

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_NetworkAdapterConfiguration",,48) 
Wscript.Echo "---------------------------------------------------------"
Wscript.Echo "Network Information"
Wscript.Echo "---------------------------------------------------------"
For Each objItem in colItems 
 If Not isNull(objItem.IPAddress) Then
  Wscript.Echo "Network Adapter            : " & objItem.Caption
  If isNull(objItem.DefaultIPGateway) Then
  Wscript.Echo "DefaultIPGateway           : "
  Else
  Wscript.Echo "DefaultIPGateway           : " & Join(objItem.DefaultIPGateway, ",")
  End If
  Wscript.Echo "DHCPEnabled                : " & objItem.DHCPEnabled
  Wscript.Echo "IPAddress                  : " & Join(objItem.IPAddress, ",")
  If isNull(objItem.IPSubnet) Then
  Wscript.Echo "IPSubnet                   : "
  Else
  Wscript.Echo "IPSubnet                   : " & Join(objItem.IPSubnet, ",")
  End If
  Wscript.Echo "MACAddress                 : " & objItem.MACAddress &  vbCrLf
 End If
Next

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_OperatingSystem",,48) 
For Each objItem in colItems 
 Wscript.Echo "---------------------------------------------------------"
 Wscript.Echo "Operating System Information"
 Wscript.Echo "---------------------------------------------------------"
 Wscript.Echo "Operating System        : " & objItem.Caption
 Wscript.Echo "Service Pack            : " & objItem.CSDVersion
 Wscript.Echo "Architecture            : " & objItem.OSArchitecture
 If objItem.OSLanguage = 1041 Then
 Wscript.Echo "Language                : " & "Japanese"
 ElseIf objItem.OSLanguage = 2057 Then
 Wscript.Echo "Language                : " & "English United Kingdom"
 ElseIf objItem.OSLanguage = 1033 Then
 Wscript.Echo "Language                : " & "English United States"
 ElseIf objItem.OSLanguage = 9 Then
 Wscript.Echo "Language                : " & "English"
 Else
 Wscript.Echo "Language                : " & "English"
 End If
 Wscript.Echo "HostName                : " & objItem.CSName
   Next

Set objWMIService = Nothing
Set colItems  = Nothing
HW情報

Win32_ComputerSystemから下記の情報を取得できる。

  • Domain情報
Domain

    Data type: string
    Access type: Read-only

    Name of the domain to which a computer belongs.

    Note  If the computer is not part of a domain, then the name of the workgroup is returned.
  • モデル
Model

    Data type: string
    Access type: Read-only

    Product name that a manufacturer gives to a computer. This property must have a value.
  • 論理CPU数
NumberOfLogicalProcessors

    Data type: uint32
    Access type: Read-only

    Number of logical processors available on the computer.

    You can use NumberOfLogicalPro
  • 物理CPU数
NumberOfProcessors

    Data type: uint32
    Access type: Read-only

    Number of physical processors currently available on a system. This is the number of enabled processors for a system, which does not include the disabled processors. If a computer system has two physical processors each containing two logical processors, then the value of NumberOfProcessors is 2 and NumberOfLogicalProcessors is 4. The processors may be multicore or they may be hyperthreading processors. For more information, see Remarks.

物理メモリ

     
TotalPhysicalMemory

    Data type: uint64
    Access type: Read-only
    Qualifiers: Units (Bytes)

    Total size of physical memory. Be aware that, under some circumstances, this property may not return an accurate value for the physical memory. For example, it is not accurate if the BIOS is using some of the physical memory. For an accurate value, use the Capacity property in Win32_PhysicalMemory instead.

これらは、下記を参照している。
Win32_ComputerSystem class
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394102(v=vs.85).aspx


Win32_NetworkAdapterConfigurationから下記の情報を取得できる。

Caption

    Data type: string
    Access type: Read-only

    Description of the CIM_Setting object?a one-line string. This property is inherited from CIM_Setting.


Win32_NetworkAdapterConfiguration class
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394217(v=vs.85).aspx

  • DHCP有効か、否か
DHCPEnabled

    Data type: boolean
    Access type: Read-only

    If TRUE, the dynamic host configuration protocol (DHCP) server automatically assigns an IP address to the computer system when establishing a network connection.
  • IP Address
IPAddress

    Data type: string array
    Access type: Read-only

    Array of all of the IP addresses associated with the current network adapter. Starting with Windows Vista, this property can contain either IPv6 addresses or IPv4 addresses. For more information, see IPv6 and IPv4 Support in WMI.

    Example IPv6 address: "2010:836B:4179::836B:4179"

        Windows Server 2003, Windows XP, and Windows 2000:  This property contains addresses in IPv4 format.

        Example: "172.16.22.0"
  • subnet
IPSubnet

    Data type: string array
    Access type: Read-only

    Array of all of the subnet masks associated with the current network adapter.

    Example: "255.255.0.0"
DefaultIPGateway

    Data type: string array
    Access type: Read-only

    Array of IP addresses of default gateways that the computer system uses.

    Example: "192.168.12.1 192.168.46.1"
  • MACAddress
    Data type: string
    Access type: Read-only

    Media Access Control (MAC) address of the network adapter. A MAC address is assigned by the manufacturer to uniquely identify the network adapter.

    Example: "00:80:C7:8F:6C:96"
SW情報

Win32_OperatingSystemから下記の情報を取得できる。

  • OS
Caption

    Data type: string
    Access type: Read-only

    Short description of the object?a one-line string. The string includes the operating system version. For example, "Microsoft Windows XP Professional Version = 5.1.2500". This property can be localized.
CSDVersion

    Data type: string
    Access type: Read-only

    NULL-terminated string that indicates the latest service pack installed on a computer. If no service pack is installed, the string is NULL. For computers running on Windows 95, this property contains a null-terminated string that provides more information about the operating system.

    Example: "Service Pack 3"
  • hostname:
CSName

    Data type: string
    Access type: Read-only

    Name of the scoping computer system.
  • OS Architecture
OSArchitecture

    Data type: string
    Access type: Read-only

    Architecture of the operating system, as opposed to the processor.

    Example: 32-bit

        Windows Server 2003, Windows 2000, Windows NT 4.0, Windows XP, and Windows Me/98/95:  This property is not available.
  • OS Language
OSLanguage

    Data type: uint32
    Access type: Read-only

1041 (0x411) Japanese
2057 (0x809)English ? United Kingdom
1033 (0x409)English ? United States
9 (0x9)English

これらは、下記を参照している。
Win32_OperatingSystem class
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394239(v=vs.85).aspx

インストール済みソフトウェアは、Win32_Productから取得できる。