C# 如何远程检索可执行程序路径

C# 如何远程检索可执行程序路径,c#,.net,wmi,C#,.net,Wmi,我正在编写一个程序,需要获取注册表中所有程序的安装日期和版本信息。我可以得到所有程序的列表,但我不知道如何访问有关程序本身的任何信息。如果我能够确定文件所在的文件路径,我将能够访问此信息。我碰巧知道我感兴趣的程序都位于C:\\Program Files(x86)\文件夹中,但它们位于我无法指定的子文件夹中。关于如何获取我正在检索的文件的文件路径,有什么想法吗 这是我的密码: public List<BSAApp> getInstalledApps( string computerNa

我正在编写一个程序,需要获取注册表中所有程序的安装日期和版本信息。我可以得到所有程序的列表,但我不知道如何访问有关程序本身的任何信息。如果我能够确定文件所在的文件路径,我将能够访问此信息。我碰巧知道我感兴趣的程序都位于
C:\\Program Files(x86)\
文件夹中,但它们位于我无法指定的子文件夹中。关于如何获取我正在检索的文件的文件路径,有什么想法吗

这是我的密码:

public List<BSAApp> getInstalledApps( string computerName )
        {
            List<BSAApp> appList = new List<BSAApp>();

            ManagementScope ms = new ManagementScope();
            ms.Path.Server = computerName;
            ms.Path.NamespacePath = "root\\cimv2";
            ms.Options.EnablePrivileges = true;
            ms.Connect();

            ManagementClass mc = new ManagementClass( "StdRegProv" );
            mc.Scope = ms;

            ManagementBaseObject mbo;
            mbo = mc.GetMethodParameters( "EnumKey" );

            mbo.SetPropertyValue( "sSubKeyName", "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths" );

            string[] subkeys = (string[])mc.InvokeMethod( "EnumKey", mbo, null ).Properties["sNames"].Value;

            if( subkeys != null )
            {
                foreach( string strKey in subkeys )
                {
                    string path = ?????
                    FileVersionInfo info = FileVersionInfo.GetVersionInfo( path );
                    appList.Add( new BSAApp( strKey, info.ProductVersion ) );                    
                }
            }

            return appList;
        }
公共列表getInstalledApps(字符串computerName)
{
List appList=新列表();
ManagementScope ms=新的ManagementScope();
ms.Path.Server=computerName;
ms.Path.NamespacePath=“root\\cimv2”;
ms.Options.EnablePrivileges=true;
Connect女士();
ManagementClass mc=新的ManagementClass(“StdRegProv”);
mc.Scope=ms;
目标管理层收购;
mbo=mc.GetMethodParameters(“EnumKey”);
mbo.SetPropertyValue(“sSubKeyName”、“软件\\Microsoft\\Windows\\CurrentVersion\\App路径”);
string[]subkeys=(string[])mc.InvokeMethod(“EnumKey”,mbo,null);
if(子键!=null)
{
foreach(子键中的字符串strKey)
{
字符串路径=?????
FileVersionInfo info=FileVersionInfo.GetVersionInfo(路径);
添加(新的BSAApp(strKey,info.ProductVersion));
}
}
返回应用程序列表;
}


但正如该线程中提到的,它也有其自身的缺点。

您是否尝试过使用WMI服务查询已安装的程序和日期?并非所有程序都安装了MIS,因此这是一个问题。是的,我正在搜索的程序中有一半没有安装MIS,因此在那里找不到。嘿,您是如何做到的?或者,您仍然有这个问题吗?我能够使用上面的方法检索一些需要的程序,并且只能满足于使用我问题中的方法的其他程序的名称。
ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT * FROM  Win32_Product");
foreach(ManagementObject mo in mos.Get())
{
  Console.WriteLine(mo["Name"]);
  Console.WriteLine(mo["InstallState"]);
}