如何使用c#通过调用该软件的注册表文件中列出的软件UninstallString来卸载软件但该进程不起作用
我正在开发一个软件,将列出所有软件安装在计算机中我现在想要使用我的程序在C#中卸载它通过在注册表项中调用该软件的卸载密钥我的程序就像那样但过程不起作用
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(); } }
试试这种方法:
Process p = new Process(); p.StartInfo.FileName = "msiexec.exe"; p.StartInfo.Arguments = "/x {F98C2FAC-6DFB-43AB-8B99-8F6907589021}/qn"; p.Start();
请参阅此链接: http : //www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/msiexec.mspx?mfr = true
HTH。
您的misexec.exe
代码的问题是运行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代码工作。
您的解决方案看起来不错,但在\qn
之前保留一个空格:
p.StartInfo.Arguments = "/x {F98C2FAC-6DFB-43AB-8B99-8F6907589021} /qn";
否则它将无法在静音模式下工作。