- WMI Fun !! -|WMI StepWMI SampleSearchWMI Fun !! GroupsAbout WMI Fun !!
Top Page >> WMI Step >> ファイルサイズを取得する
ファイルサイズを取得する
Topics

ファイルサイズを取得するサンプルです。CIM_DataFileクラスを使用します。


Sample Code

Private Sub Command1_Click()

Dim CdfSet As SWbemObjectSet
Dim Cdf As SWbemObject
Dim Locator As SWbemLocator
Dim Service As SWbemServices
Dim MesStr As String

Set Locator = New WbemScripting.SWbemLocator
Set Service = Locator.ConnectServer
Set CdfSet = Service.ExecQuery("Select * From CIM_DataFile Where Name = 'c:\\boot.ini'")

For Each Cdf In CdfSet
    
    MesStr = "ファイル名:" & Cdf.Name & vbCrLf & _
            "8.3ファイル形式:" & Cdf.EightDotThreeFileName & vbCrLf & _
            "ファイルサイズ:" & Cdf.FileSize & vbCrLf & _
            "ファイルの種類:" & Cdf.FileType & vbCrLf

Next

MsgBox "ファイルサイズです。" & vbCrLf & _
            vbCrLf & MesStr & vbCrLf & "ですよ。"

Set CdfSet = Nothing
Set Cdf = Nothing
Set Service = Nothing
Set Locator = Nothing

End Sub

Comment

実行するとcドライブにある、boot.iniファイルを検索してファイルサイズをを表示します。今回のサンプルでは同時に8.3形式のファイル名とファイルの種類も表示するようにしてあります。


WMI を本で勉強したい方へ。 Windows PowerShellインアクション を読んでみては?
なかなか WMI のことが乗っている書籍は少ないですが…管理系業務に係る方には楽しめるかも?
パソコンで目が疲れたら、ブルーベリーアイ
『ブルーベリーアイ』1粒中ビルベリーエキス160mg【楽天シニア市場】
 ^ Copyright(C) 1997-2008 とお All rights reserved. <<