MSI 安装程序选项 - 卸载应用程序 [英] MSI installer option- uninstalling an application

查看:82
本文介绍了MSI 安装程序选项 - 卸载应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

If I run the code below I'm pretty sure I'm supposed to get the Product Name and GUID (ex. App Path | {xxx}) for the application. But I'm only getting the path and no GUID is shown. Can someone help me?

// 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 值是通过 添加/删除程序 卸载应用程序时执行的值.正如您的控制台输出所示,它是可执行文件的路径.

I believe the UninstallString value is what gets executed when uninstalling an application via Add/Remove Programs. As your console output shows, it's the path to an executable.

您检索产品 ID 的方式...

The way you are retrieving the product ID...

string prdctId = uninstlString.Substring(12);

...因此,这是不正确的,因为您采用的是部分路径.您需要传递给 MsiExec.exe/x 的是产品代码,即注册表项名称本身,即....

...therefore, is incorrect because you are taking a partial path. What you need to pass to MsiExec.exe /x is the product code, which is the registry key name itself, i.e....

string prdctId = keyName;

如果您从 Command Prompt 调用该命令行,我很确定大括号将需要在产品代码周围加上引号;我不确定在直接调用可执行文件时是否需要这样做,但它不会受到伤害...

If you were invoking that command line from Command Prompt I'm pretty sure the curly brackets would necessitate putting quotes around the product code; I'm not sure if you'll need to do so when invoking the executable directly, but it can't hurt...

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

这篇关于MSI 安装程序选项 - 卸载应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆