Option Strict On Imports System Imports System.Text Imports System.Management Module Module1 Sub Main() Dim serverName As String = InputBox("サーバー名を指定", "空き容量確認", "localhost") Dim options As ConnectionOptions = Nothing If New String() {"localhost", ".", ""}.Contains(serverName.ToLowerInvariant()) Then options = Nothing Else 'My.User.InitializeWithWindowsUser() 'Dim userName As String = My.User.Name Dim userName As String = InputBox("ユーザー名", "空き容量確認", "Administrator") Dim password As String = InputBox("パスワード", "空き容量確認") options = New ConnectionOptions() With {.Username = userName, .Password = password} End If Dim path As String = "\\" & serverName & "\root\cimv2" Dim scope As New ManagementScope(path, options) Dim query As New ObjectQuery("SELECT * FROM Win32_LogicalDisk WHERE DriveType = 3 OR DriveType = 4") Dim sb As New StringBuilder() sb.AppendLine("ドライブ|総容量|空き容量") Using mos As New ManagementObjectSearcher(scope, query), col = mos.Get() For Each mo In col sb.AppendLine(String.Format("{0}|{1:N0} Bytes|{2:N0} Bytes", mo("DeviceID"), mo("Size"), mo("FreeSpace"))) mo.Dispose() Next End Using MsgBox(sb.ToString(), MsgBoxStyle.Information, "空き容量確認") End Sub End Module