#navi(../)
* Win32_ComputerSystemのサンプルスクリプト [#t4af56ba]
WMIを使ったWin32_ComputerSystem内のコンピュータ名、ユーザ名、ドメイン、ドメインのロールを表示する、サンプルスクリプトを以下に記します。

#contents
#htmlinsertpcsp(win-top.html,win-sp.html)

* 関連記事 [#p8fe9672]
-[[PowerShellでWMIを使用するサンプル>PowerShell/PowerShellでWMIを使用するサンプル]]
-[[Win32_ComputerSystemのサンプルスクリプト>WSH/Win32_ComputerSystemのサンプルスクリプト]]
-[[Win32_ComputerSystemProductのサンプルスクリプト>WSH/Win32_ComputerSystemProductのサンプルスクリプト]]
-[[Win32_OperatingSystemのサンプルスクリプト>WSH/Win32_OperatingSystemのサンプルスクリプト]]
-[[Win32_BIOSのサンプルスクリプト>WSH/Win32_BIOSのサンプルスクリプト]]
-[[Win32_LogicalDiskのサンプルスクリプト>WSH/Win32_LogicalDiskのサンプルスクリプト]]
-[[Win32_Processorのサンプルスクリプト>WSH/Win32_Processorのサンプルスクリプト]]
-[[Win32_NetworkAdapterConfigurationのサンプルスクリプト>WSH/Win32_NetworkAdapterConfigurationのサンプルスクリプト]]
-[[Win32_DiskDriveのサンプルスクリプト>WSH/Win32_DiskDriveのサンプルスクリプト]]


* Win32_ComputerSystemを使ったサンプルスクリプト [#f6efaf9c]

以下にWin32_ComputerSystemを使用したサンプルスクリプトを記します。~
本サンプルスクリプトでは、以下の5つの値を表示しています。
-コンピュータ名
-ユーザ名
-ドメイン名
-プロセッサ数
-ドメインのロール

** サンプルスクリプト [#f321adeb]
#ref(comsys.vbs)
 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_ComputerSystem", , 48)
 
 For Each item In items
   WScript.Echo("コンピュータ名: " & item.Name)
   WScript.Echo("ユーザ名: " & item.UserName)
   WScript.Echo("ドメイン名: " & item.Domain)
   WScript.Echo("プロセッサ数: " & item.NumberOfProcessors)
   Select Case item.DomainRole
     ' https://technet.microsoft.com/en-us/library/ee198796.aspx
     Case 0
       desc = "Stand-alone workstation"
     Case 1
       desc = "Member workstation"
     Case 2
       desc = "Stand-alone server"
     Case 3
       desc = "Member server"
     Case 4
       desc = "Backup domain controller"
     Case 5
       desc = "Primary domain controller"
   End Select
   WScript.Echo("ドメインのロール: " & desc)
 Next
 
 Set item = Nothing
 Set oService = Nothing
 Set oLocater = Nothing

** 実行例 [#xc437100]
cscriptを使用して実行した時の出力です。
 PS C:\Users\sakura\Desktop> cscript .\comsys.vbs
 Microsoft (R) Windows Script Host Version 5.8
 Copyright (C) Microsoft Corporation. All rights reserved.
 
 コンピュータ名: THINKPAD
 ユーザ名: THINKPAD\sakura
 ドメイン名: WORKGROUP
 プロセッサ数: 1
 ドメインのロール: Stand-alone workstation

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

#htmlinsertpcsp(win-btm.html,win-sp.html)

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS