C# MSI安装程序选项-卸载应用程序

C# MSI安装程序选项-卸载应用程序,c#,registry,uninstallation,windows-installer,C#,Registry,Uninstallation,Windows Installer,如果我运行下面的代码,我很确定我应该获得应用程序的产品名称和GUID(例如,App Path |{xxx})。但我只获取路径,没有显示GUID。有人能帮我吗 // search in: LocalMachine_64 key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"); foreach (String keyName in key.Ge

如果我运行下面的代码,我很确定我应该获得应用程序的产品名称和GUID(例如,App Path |{xxx})。但我只获取路径,没有显示GUID。有人能帮我吗

// search in: LocalMachine_64
key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall");
foreach (String keyName in key.GetSubKeyNames())
{
    RegistryKey subkey = key.OpenSubKey(keyName);
    displayName = Convert.ToString(subkey.GetValue("DisplayName"));
    uninstlString = Convert.ToString(subkey.GetValue("UninstallString"));

    if (p_name.Equals(displayName, StringComparison.OrdinalIgnoreCase))
    {
        Console.WriteLine(subkey.GetValue("UninstallString"));
        //string prdctId = uninstlString.Substring((uninstlString.IndexOf("{")));
        string prdctId = uninstlString.Substring(12);
        uninstallProcess.StartInfo.FileName = "MsiExec.exe";
        uninstallProcess.StartInfo.Arguments = " /x " + prdctId + " /quiet /norestart";
        uninstallProcess.StartInfo.UseShellExecute = true;
        uninstallProcess.Start();
        uninstallProcess.WaitForExit();
        break;
        //Console.WriteLine(subkey.GetValue("UninstallString"));
    }
}
这是我运行代码得到的图像

我相信
UninstallString
值是通过
Add/Remove Programs
卸载应用程序时执行的值。正如控制台输出所示,它是指向可执行文件的路径

您检索产品ID的方式

string prdctId = uninstlString.Substring(12);
…因此,是不正确的,因为您选择的是部分路径。您需要传递给
MsiExec.exe/x
的是产品代码,它是注册表项名称本身,即

string prdctId = keyName;
如果您在
命令提示符下调用该命令行
,我很确定,花括号将需要在产品代码周围加引号;我不确定在直接调用可执行文件时是否需要这样做,但这不会影响

uninstallProcess.StartInfo.Arguments = " /x \"" + prdctId + "\" /quiet /norestart";

很抱歉,那么如何获取keyName…?您已经有了
keyName
。这是您的
foreach
循环迭代变量。哦,对了。。那么卸载字符串是否不必要?是和否。您的代码不需要以您现在的方式调用
MsiExec.exe
,但是您可以执行存储在
UninstallString
中的命令行,而不必使用
MsiExec.exe
,尽管你只能任由卸载程序提供的东西摆布,而不是
MsiExec.exe
的一致界面。我已经尝试过了…仍然没有卸载:不管你问多少次,你仍然会得到类似的答案<代码>卸载字符串是您运行以卸载该应用程序的内容。您不能/不应该将其拆开,尝试处理它,等等。从这一连串的问题中可以清楚地看出,您(个人、您的团队/部门/单位/公司)并不拥有要卸载的应用程序。(如果您这样做了,您就不会在注册表中查找它们的卸载信息)。你想悄悄卸载你不拥有的应用程序,这让我怀疑你的动机。如果有合理的理由这样做,请编辑您现有的问题之一,并使该用例清晰。