如何检查安装程序的C#

Nem*_*emo 8 c#

我需要按程序名称(添加或删除程序中显示的名称)检查程序的安装位置.什么是最好的方法,以便它适用于所有语言.

Oli*_*ver 13

看一下注册表

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
Run Code Online (Sandbox Code Playgroud)

只需迭代所有子键,然后查看值DisplayNameInstallLocation.在这里你可以找到你想要的信息以及更多;-)


Lei*_*igh 9

为了增加Oliver的答案,我在静态方法中包含了这个检查.

public static bool IsProgramInstalled(string programDisplayName) {

    Console.WriteLine(string.Format("Checking install status of: {0}",  programDisplayName));
    foreach (var item in Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall").GetSubKeyNames()) {

        object programName = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + item).GetValue("DisplayName");

        Console.WriteLine(programName);

        if (string.Equals(programName, programDisplayName)) {
            Console.WriteLine("Install status: INSTALLED");
            return true;
        }
    }
    Console.WriteLine("Install status: NOT INSTALLED");
    return false;
}
Run Code Online (Sandbox Code Playgroud)