如果我安装名为'ABC'的软件,如果我提供软件名称'ABC'作为输入,我怎样才能在C#.Net中获得完整的安装路径?
答案 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;