获取已安装软件的路径c#.net

时间:2011-05-26 10:28:33

标签: c# windows system.diagnostics

如果我安装名为'ABC'的软件,如果我提供软件名称'ABC'作为输入,我怎样才能在C#.Net中获得完整的安装路径?

1 个答案:

答案 0 :(得分:1)

你可以尝试下面的

using System.Management;

    ManagementObjectSearcher MyWMIQuery = new ManagementObjectSearcher("SELECT * FROM Win32_Product") ;
    ManagementObjectCollection MyWMIQueryCollection = MyWMIQuery.Get();
    foreach(ManagementObject MyMO in MyWMIQueryCollection) 
    {
       if(MyMO["Name"].ToString()=="ABC")
        Console.WriteLine("InstallLocation : " + (MyMO["InstallLocation"] == null ? " " : MyMO["InstallLocation"].ToString()));

        Console.ReadLine();
    }
    MyWMIQueryCollection = null;
    MyWMIQuery = null;