#navi(../)
* Win32_OperatingSystemのサンプルスクリプト [#fbff1f53]
WMIを使ったWin32_OperatingSystemでオペレーティングシステムに関する情報を表示するサンプルスクリプトを以下に記します。

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

* 関連記事 [#y04148d4]
-[[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_OperatingSystemを使ったサンプルスクリプト [#x030a417]

以下にWin32_OperatingSystemを使用したサンプルスクリプトを記します。~
本サンプルスクリプトでは、以下の値を表示しています。
-Windows名
-ビルド番号
-バージョン
-OSアーキテクチャ
-シリアル番号
-レジストユーザ
-Windowsディレクトリ
-システムディレクトリ
-トータルメモリサイズ
-フリーメモリ
-仮想メモリサイズ
-フリー仮想メモリ


** サンプルスクリプト [#c731e854]
#ref(opesys.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_OperatingSystem", , 48)
 
 For Each item In items
   WScript.Echo("Windows名: " & item.Caption)
   WScript.Echo("ビルド番号: " & item.BuildNumber)
   WScript.Echo("バージョン: " & item.Version)
   WScript.Echo("OSアーキテクチャ: " & item.OSArchitecture)
   WScript.Echo("シリアル番号: " & item.SerialNumber)
   WScript.Echo("レジストユーザ: " & item.RegisteredUser)
   WScript.Echo("Windowsディレクトリ: " & item.WindowsDirectory)
   WScript.Echo("システムディレクトリ: " & item.SystemDirectory)
   WScript.Echo("トータルメモリサイズ: " & item.TotalVisibleMemorySize)
   WScript.Echo("フリーメモリ: " & item.FreePhysicalMemory)
   WScript.Echo("仮想メモリサイズ: " & item.TotalVirtualMemorySize)
   WScript.Echo("フリー仮想メモリ: " & item.FreeVirtualMemory)
 Next
 
 Set item = Nothing
 Set oService = Nothing
 Set oLocater = Nothing

** 実行例 [#c056dc9f]
cscriptを使用して実行した時の出力です。
 PS C:\Users\sakura\Desktop> cscript .\opesys.vbs
 Microsoft (R) Windows Script Host Version 5.8
 Copyright (C) Microsoft Corporation. All rights reserved.
 
 Windows名: Microsoft Windows 8.1
 ビルド番号: 9600
 バージョン: 6.3.9600
 OSアーキテクチャ: 64 ビット
 シリアル番号: 11111-22222-33333-AAAAA
 レジストユーザ: sakura@foobarhoge
 Windowsディレクトリ: C:\WINDOWS
 システムディレクトリ: C:\WINDOWS\system32
 トータルメモリサイズ: 8230752
 フリーメモリ: 5901876
 仮想メモリサイズ: 9541472
 フリー仮想メモリ: 6955676

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

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

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