2010-12-14 9 views
0

リモートシステム上のファイルをWMIとC#を使用してファイル名で検索するにはどうすればよいですか?C#でWMIを使用してファイル名でリモートシステム上のファイルを検索する方法は?

+0

あなたにこれに関する詳細を教えてもらえますか? – jcolebrand

+0

として、WMIを使用してリモートシステムでプロセスを開始および終了することができます。私は、ファイルとしてusngファイル名をキーワードとして検索することで、リモートシステムのファイルのパスを取得するために、このことをextndします... !! – rakzz

答えて

2

このコードを試してthisをチェックしてください。 WMIコードクリエーター(私の評判が<のためリンクできないため、googleをチェックしてください)は、簡単にWMIクエリーをテストできます。

using System; 
using System.Management; 
namespace WMISample 
{ 
    public class MyWMIQuery 
    { 
     public static void Main() 
     { 
      try 
      { 
      ConnectionOptions oConn = new ConnectionOptions(); 
      oConn.Impersonation = ImpersonationLevel.Impersonate; 
      oConn.EnablePrivileges = true; 
       string[] arrComputers = "clientName"}; 
       foreach (string strComputer in arrComputers) 
       { 
        Console.WriteLine("=========================================="); 
        Console.WriteLine("Computer: " + strComputer); 
        Console.WriteLine("=========================================="); 


         ManagementObjectSearcher searcher = new ManagementObjectSearcher 
         ( 
          new ManagementScope("\\\\" + strComputer + "\\root\\CIMV2", oConn), 
          new ObjectQuery(@"SELECT * FROM CIM_DataFile WHERE Name = 'WhatyouWant.ToSearch'") 
         ); 


        foreach (ManagementObject queryObj in searcher.Get()) 
        { 
         Console.WriteLine("-----------------------------------"); 
         Console.WriteLine("CIM_DataFile instance"); 
         Console.WriteLine("-----------------------------------"); 
         Console.WriteLine("Path: {0}", queryObj["Path"]); 
        } 
       } 
      } 
      catch(ManagementException err) 
      { 
       MessageBox.Show("An error occurred while querying for WMI data: " + err.Message); 
      } 
     } 
    } 
} 
+0

ありがとうございました...! – rakzz

関連する問題