我想使用我的代码卸载软件,我的代码正在处理unistallString" msiexec.exe / x {your-product-code-guid}"和" C:\ Program Files \ TeamViewer \ uninstall.exe \"。
但现在正在处理uninstallString,如" C:\ Program Files \ Common Files \ Adobe AIR \ Versions \ 1.0 \ Resources \ Adobe AIR Updater.exe -arp:uninstall" ..
这个抛出异常("系统找不到指定的文件")
(这里S = MyUnistallString)
try
{
s = s.Replace("\"", ""); //Replace <">
string uninstallArguments = null;
string uninstallAssembly = null;
if (!s.Contains("/"))
{
uninstallAssembly = s;
}
else
{
string[] uninstallArgumentsArray = s.Split(new string[] { " /" }, StringSplitOptions.RemoveEmptyEntries); // Split for any parameters
if (uninstallArgumentsArray.Count() > 1)
{
for (int count = 1; count < uninstallArgumentsArray.Count(); count++)
{
uninstallArguments = "/" + uninstallArgumentsArray[count];
}
}
uninstallAssembly = uninstallArgumentsArray[0];
}
if (!string.IsNullOrWhiteSpace(uninstallAssembly))
{
Process uninstallProcess = new Process();
uninstallProcess.StartInfo = new ProcessStartInfo();
uninstallProcess.StartInfo.FileName = uninstallAssembly;
uninstallProcess.StartInfo.Arguments = uninstallArguments;
uninstallProcess.Start();
}
}
catch (Exception)
{
}
答案 0 :(得分:0)
所以,我发现了我的错误,也会帮助其他人
在
之后添加if(!s.Contains(“/”))
if(s.Contains(" -"))
{
string[] uninstallArgumentsArray = s.Split(new string[] { " -" }, StringSplitOptions.RemoveEmptyEntries); // Split for any parameters
if (uninstallArgumentsArray.Count() > 1)
{
for (int count = 1; count < uninstallArgumentsArray.Count(); count++)
{
uninstallArguments += " -" + uninstallArgumentsArray[count];
}
}
此代码适用于所有UnInstallString