vbsの作法 その80

# 概要
vbsの作法、調べてみた。
vbs見つけたので、やってみた。

# 参考にしたページ

https://qiita.com/yaju/items/6cb9edaaa229cea3da78

# 環境
windows11

# サンプルコード
```
Option Explicit
Dim InfoStr
GetSystemInfo InfoStr
GetDrivesInfoByType InfoStr
WScript.Echo InfoStr

Function GetSystemInfo(ByRef Str)
	Dim oLocator
	Dim oService
	Dim oClassSet
	Dim oClass
	Dim objShell
	Dim strComputer
	Dim strValue
	Dim makerName
	Dim modelName
	Dim objRegistry
	Dim strKeyPath
	Dim strValueName
	const HKEY_LOCAL_MACHINE = &H80000002
	GetSystemInfo = False
	Set oLocator = Wscript.CreateObject("WbemScripting.SWbemLocator")
	Set oService = oLocator.ConnectServer
	Set oClassSet = oService.ExecQuery("Select * From Win32_ComputerSystem")
	For Each oClass In oClassSet
		makerName = oClass.Manufacturer
		modelName = oClass.Model
	Next
	strComputer = "."
	Set objShell = WScript.CreateObject("WScript.Shell")
	Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
	strKeyPath = "Software\Microsoft\Windows\CurrentVersion\OEMInformation"
	strValueName = "Manufacturer"
	objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue
	If Not IsNull(strValue) Then
		makerName = objShell.RegRead("HKEY_LOCAL_MACHINE\" & strKeyPath & "\" & strValueName)
	End If
	strValueName = "Model"
	objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue
	If Not IsNull(strValue) Then
		modelName = objShell.RegRead("HKEY_LOCAL_MACHINE\" & strKeyPath & "\" & strValueName)
	End If
	Str = Str & "メーカー: " & makerName & vbCrLf & "モデル: " & modelName & vbCrLf & vbCrLf
	Set oLocator = Nothing
	Set oService = Nothing
	Set oClassSet = Nothing
	Set objShell = Nothing
	GetSystemInfo = True
End Function

Function GetDrivesInfoByType(ByRef Str)
	Dim strComputer
	Dim objWMIService
	Dim DiskDrives
	Dim DiskDrive
	Dim strDeviceID
	Dim Query
	Dim DiskPartitions
	Dim DiskPartition
	Dim LogicalDisks
	Dim LogicalDisk
	Dim colDiskDrives
	Dim objDiskDrive
	GetDrivesInfoByType = False
	strComputer = "."
	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
	Query = "SELECT * FROM Win32_DiskDrive"
	Set DiskDrives = objWMIService.ExecQuery(Query)
	For Each DiskDrive in DiskDrives
		strDeviceID = Replace(DiskDrive.DeviceID, "\", "\\")
		Query = "ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & strDeviceID
		Query = Query & """} WHERE AssocClass=Win32_DiskDriveToDiskPartition"
		Set DiskPartitions = objWMIService.ExecQuery(Query)
		For Each DiskPartition in DiskPartitions
			Query = "ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & DiskPartition.DeviceID
			Query = Query & """} WHERE AssocClass=Win32_LogicalDiskToPartition"
			Set LogicalDisks = objWMIService.ExecQuery(Query)
			For Each LogicalDisk In LogicalDisks
				LinesAdd Str, "ドライブ:" & LogicalDisk.DeviceID
				Query = "Select * from Win32_DiskDrive WHERE DeviceID = '" & strDeviceID & "'"
				Set colDiskDrives = objWMIService.ExecQuery(Query)
				For Each objDiskDrive in colDiskDrives
					LinesAdd Str, "HDDの型番: " & objDiskDrive.InterfaceType
					LinesAdd Str, "モデル: " & objDiskDrive.Model
					LinesAdd Str, "サイズ: " & Int(objDiskDrive.Size / 1000000000) & " GB"
					LinesAdd Str, "状態: " & objDiskDrive.Status
					LinesAdd Str, ""
				Next
				GetDrivesInfoByType = True
			Next
			Set LogicalDisks = Nothing
		Next
		Set DiskPartitions = Nothing
		Exit For
	Next
	Set DiskDrives = Nothing
	Set objWMIService = Nothing
End Function

Sub LinesAdd(ByRef S, V)
	S = S & V & vbNewLine
End Sub





```

# 写真

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/18104/95e62194-6af9-b3dc-a9c4-d73eb7dd2872.png)


以上。