このエントリーをはてなブックマークに追加


Win32_ComputerSystemProductのサンプルスクリプト

WMIを使ったWin32_ComputerSystemProductでマシンに関する情報を表示するサンプルスクリプトを以下に記します。


関連記事

Win32_ComputerSystemProductを使ったサンプルスクリプト

以下にWin32_ComputerSystemProductを使用したサンプルスクリプトを記します。
本サンプルスクリプトでは、以下の4つの値を表示しています。

  • プロダクト名
  • プロダクトのバージョン
  • 製品ID
  • ベンダー

サンプルスクリプト

hostname="."	' dotは自機を示す
' uid = "username"
' pwd = "password"
Set oLocater = CreateObject("WbemScripting.SWbemLocator")
Set oService = oLocater.ConnectServer(hostname, "root/cimv2")
' Set oService = oLocater.ConnectServer(hostname, "root/cimv2", uid, pwd)	'ユーザ、パスワード設定をする場合
oService.Security_.ImpersonationLevel = 3	' デフォルト値は3のため省略可能

Set items = oService.ExecQuery("Select * From Win32_ComputerSystemProduct", , 48)

For Each item In items
  WScript.Echo("プロダクト名: " & item.Name)
  WScript.Echo("プロダクトのバージョン: " & item.Version)
  WScript.Echo("製品ID: " & item.IdentifyingNumber)
  WScript.Echo("ベンダー: " & item.Vendor)
Next

Set item = Nothing
Set oService = Nothing
Set oLocater = Nothing

実行例

cscriptを使用して実行した時の出力です。

PS C:\Users\sakura\Desktop> cscript .\comsyspro.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

プロダクト名: 3254CTO
プロダクトのバージョン: ThinkPad Edge E430
製品ID: MP20G0P
ベンダー: LENOVO
PS C:\Users\sakura\Desktop>

以上、Win32_ComputerSystemProductを使ったサンプルスクリプトでした。



添付ファイル: filecomsyspro.vbs 481件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2015-04-19 (日) 17:19:28