Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
(c#)如何检查某个exe是否位于用户计算机上?_C# - Fatal编程技术网

(c#)如何检查某个exe是否位于用户计算机上?

(c#)如何检查某个exe是否位于用户计算机上?,c#,C#,我想知道如何测试并查看某个exe是否位于用户计算机上?例如,如果我想查找skype,我会运行如下函数: if(checkForSkypeonUsrcomputer("Skype.exe")==true){ //Script detects skype.exe on users computer } else { //Script detects skype.exe is not on users computer } checkForSkypeonUsrcomputer(s

我想知道如何测试并查看某个exe是否位于用户计算机上?例如,如果我想查找skype,我会运行如下函数:

if(checkForSkypeonUsrcomputer("Skype.exe")==true){
    //Script detects skype.exe on users computer 
} else {
    //Script detects skype.exe is not on users computer 
}

checkForSkypeonUsrcomputer(string exetype)
{
    CheckForExeOnUsersComputer(exetype);
    return TrueOrFalse;
}
^这只是一个例子,试图解释我想做什么^


我到处寻找解决方案,但找不到。

尝试在注册表中的“卸载”键下查找该应用程序。 HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall 此处列出了所有可卸载的应用程序,您可以通过其显示名称找到它们,例如:

private string FindByDisplayName(RegistryKey parentKey, string name)
         {
             string[] nameList = parentKey.GetSubKeyNames();
             for (int i = 0; i < nameList.Length; i++)
             {
                 RegistryKey regKey =  parentKey.OpenSubKey(nameList[i]);
                 try
                 {
                     if (regKey.GetValue("DisplayName").ToString() == name)
                     {
                         return regKey.GetValue("InstallLocation").ToString();
                     }
                 }
                 catch { }
             }
             return "";
         }
私有字符串FindByDisplayName(注册表项parentKey,字符串名)
{
字符串[]名称列表=parentKey.GetSubKeyNames();
for(int i=0;i
让我知道这是否适合您:)

您可以根据扩展名筛选结果,甚至还可以根据文件名筛选结果


Directory.GetFiles(dirpath).Where(file=>file.EndsWith(“.ext”))

尝试此页面“如何遍历directorys”。如果存在这样一个函数,一旦得到答案,您会怎么做?与其采取零碎的方法,不如给我们一个关于你试图实现的目标的大局图。可能有一种解决方案不是以“在用户的计算机上查找exe”开头的。