通过调用软件UninstallString列在软件的注册表文件使用C#如何卸载软件,但这个过程是不工作 [英] How to uninstall Software using c# by calling Software UninstallString Listed in Registry file of that Software But the Process Is Not Working

查看:284
本文介绍了通过调用软件UninstallString列在软件的注册表文件使用C#如何卸载软件,但这个过程是不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个软件,将列出所有的软件安装 计算机 现在我想用我的程序在C#中通过将其卸载 调用该软件在卸载关键 注册表项 我的计划是 这样的,但这个过程是不工作

  VAR UninstallDir =在msiexec.exe / I {F98C2FAC-6DFB-43AB-8B99-8F6907589021};
字符串_path =;
字符串_args =;
过程_Process =新工艺();
如果(UninstallDir = NULL和放大器;!&安培;!UninstallDir =)
{
    如果(UninstallDir.StartsWith(rundll32.exe的))
    {
        _args = ConstructPath(UninstallDir);
        _Process.StartInfo.FileName = Environment.SystemDirectory.ToString()+\\的explorer.exe;
        _Process.StartInfo.Arguments = Environment.SystemDirectory.ToString()+\\+ UninstallDir;
        _Process.Start();
    }
    否则,如果(UninstallDir.StartsWith(msiexec.exe的))
    {
        _args = ConstructPath(UninstallDir);
        _Process.StartInfo.FileName = Environment.SystemDirectory.ToString()+\\ cmd.exe的;
        _Process.StartInfo.Arguments = Environment.SystemDirectory.ToString()+\\+ UninstallDir;
        _Process.Start();
    }
    其他
    {
        //字符串路径= ConstructPath(UninstallDir);
        _path = ConstructPath(UninstallDir);
        如果(_path.Length大于0)
        {
            _Process.StartInfo.FileName = _path;
            _Process.StartInfo.UseShellExecute = FALSE;
            _Process.Start();
        }
    }
 

解决方案

你的 misexec.exe code的问题是,运行 CMD.EXE someprogram.exe 不启动该程序,因为cmd.exe的不执行参数传递给它。但是,你可以告诉它通过使用/ C开关看到这里。你的情况,这应该工作:

  _Process.StartInfo.FileName = Environment.SystemDirectory.ToString()+\\ cmd.exe的;
    _Process.StartInfo.Arguments =/ C+ Environment.SystemDirectory.ToString()+\\+ UninstallDir;
 

在哪里我所做的只是添加 / C (后用一个空格),以自变量的开始。我不知道如何让你的RUNDLL32.EXE code到工作,但是。

I am developing a software that will list all the software install in Computer now i want to Uninstall it using my Program In C# by calling the Uninstall Key of that software in Registry Key My Program Is Like That But the Process Is Not Working

var UninstallDir = "MsiExec.exe /I{F98C2FAC-6DFB-43AB-8B99-8F6907589021}";
string _path = "";
string _args = "";
Process _Process = new Process();
if (UninstallDir != null && UninstallDir != "")
{
    if (UninstallDir.StartsWith("rundll32.exe"))
    {
        _args = ConstructPath(UninstallDir);
        _Process.StartInfo.FileName = Environment.SystemDirectory.ToString() + "\\explorer.exe";
        _Process.StartInfo.Arguments = Environment.SystemDirectory.ToString() + "\\" + UninstallDir;
        _Process.Start();
    }
    else if (UninstallDir.StartsWith("MsiExec.exe"))
    {
        _args = ConstructPath(UninstallDir);
        _Process.StartInfo.FileName = Environment.SystemDirectory.ToString() + "\\cmd.exe";
        _Process.StartInfo.Arguments = Environment.SystemDirectory.ToString() + "\\" + UninstallDir;
        _Process.Start();
    }
    else
    {
        //string Path = ConstructPath(UninstallDir);
        _path = ConstructPath(UninstallDir);
        if (_path.Length > 0)
        {
            _Process.StartInfo.FileName = _path;
            _Process.StartInfo.UseShellExecute = false;
            _Process.Start();
        }
    }

解决方案

The problem with your misexec.exe code is that running cmd.exe someprogram.exe doesn't start the program because cmd.exe doesn't execute arguments passed to it. But, you can tell it to by using the /C switch as seen here. In your case this should work:

    _Process.StartInfo.FileName = Environment.SystemDirectory.ToString() + "\\cmd.exe";
    _Process.StartInfo.Arguments = "/C " + Environment.SystemDirectory.ToString() + "\\" + UninstallDir;

Where all I did was add /C (with a space after) to the beginning of the arguments. I don't know how to get your rundll32.exe code to work, however.

这篇关于通过调用软件UninstallString列在软件的注册表文件使用C#如何卸载软件,但这个过程是不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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