WMI および C# を使用してリモート コンピューターのフォルダー サイズを照会する方法。WMI を使用して、リモート システムの C:\Users にある各ユーザーのフォルダー サイズを見つける必要があります。
Win32_Directory 、 CMI_DataFile を試しましたが、目的の答えが見つかりませんでした。助けてください!!
CIM_DataFileWMIを使用してフォルダーのサイズを取得するには、クラスを使用してファイルを反復処理してから、FileSizeプロパティから各ファイルのサイズを取得する必要があります。
このサンプルを試してください(このコードは再帰的ではありません。そのようなタスクはあなたに任せます)。
using System; 
using System.Collections.Generic;
using System.Management;
using System.Text;
namespace GetWMI_Info
{
    class Program
    {
// Directory is a type of file that logically groups data files 'contained' in it, 
// and provides path information for the grouped files.
        static void Main(string[] args)
        {
            try
            {
                string ComputerName = "localhost";
                ManagementScope Scope;                
                if (!ComputerName.Equals("localhost", StringComparison.OrdinalIgnoreCase)) 
                {
                    ConnectionOptions Conn = new ConnectionOptions();
                    Conn.Username  = "";
                    Conn.Password  = "";
                    Conn.Authority = "ntlmdomain:DOMAIN";
                    Scope = new ManagementScope(String.Format("\\\\{0}\\root\\CIMV2", ComputerName), Conn);
                }
                else
                    Scope = new ManagementScope(String.Format("\\\\{0}\\root\\CIMV2", ComputerName), null);
                Scope.Connect();
                string Drive= "c:";
                //look how the \ char is escaped. 
                string Path="\\\\FolderName\\\\";
                UInt64 FolderSize = 0;
                ObjectQuery Query = new ObjectQuery(string.Format("SELECT * FROM CIM_DataFile Where Drive='{0}' AND Path='{1}' ", Drive, Path));
                ManagementObjectSearcher Searcher = new ManagementObjectSearcher(Scope, Query);
                foreach (ManagementObject WmiObject in Searcher.Get())
                {
                    Console.WriteLine("{0}", (string)WmiObject["FileName"]);// String
                    FolderSize +=(UInt64)WmiObject["FileSize"];
                }
                Console.WriteLine("{0,-35} {1,-40}", "Folder Size", FolderSize.ToString("N"));
            }
            catch (Exception e)
            {
                Console.WriteLine(String.Format("Exception {0} Trace {1}",e.Message,e.StackTrace));
            }
            Console.WriteLine("Press Enter to exit");
            Console.Read();
        }
    }
}