我試圖通過Visual Studio和可能的CMD卸載使用C#的程序。我做了幾次嘗試,但沒有得到任何東西。如何使用C#卸載程序?
嘗試#1:
RegistryKey localMachine = Registry.LocalMachine;
string productsRoot = @"C:\Program Files(x86)\Microsoft\XML";
RegistryKey products = localMachine.OpenSubKey(productsRoot);
string[] productFolders = products.GetSubKeyNames();
foreach (string p in productFolders)
{
RegistryKey installProperties = products.OpenSubKey(p + @"\InstallProperties");
if (installProperties != null)
{
string displayName = (string)installProperties.GetValue("DisplayName");
if ((displayName != null) && (displayName.Contains("XML")))
{
string uninstallCommand = (string)installProperties.GetValue("UninstallString");
return uninstallCommand;
}
}
}
基於:https://sites.google.com/site/msdevnote/home/programmatically-uninstall-programs-with-c
嘗試#2:基於
Process p = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = "cmd.exe";
info.RedirectStandardInput = true;
info.UseShellExecute = false;
p.StartInfo = info;
p.Start();
using (StreamWriter sw = p.StandardInput)
{
if (sw.BaseStream.CanWrite)
{
sw.WriteLine("wmic");
sw.WriteLine("product get name");
sw.WriteLine("XML" call uninstall);
}
}
:http://www.sevenforums.com/tutorials/272460-programs-uninstall-using-command-prompt-windows.html和Execute multiple command lines with the same process using .NET
我使用Visual Studio代碼從主要我運行現在就來。謝謝你的幫助。
鏈接1和2有我我需要的東西! – sam