简体   繁体   中英

Uninstall program using System.Diagnostic.Process and its UninstallString in C#

Im Using this Code (Tried this too) To uninstall a program using my Uninstall string in my registry, but there's some errors in the code of the first link. Im Trying to fix it but I'm having trouble figuring out what would be in file name, and what would be in Arguments. My UninstalString is:

rundll32.exe dfshim.dll,ShArpMaintain ItemMan.Client.application, Culture=neutral, PublicKeyToken=4f1069eb693dc232, processorArchitecture=msil

The directory in the registry is

CurrentUser\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\9e648bbdf5bc3053

The part I'm having trouble with:

            System.Diagnostics.Process FProcess = new System.Diagnostics.Process();
            FProcess.StartInfo.FileName = "rundll32.exe"; (Dont know if this is right though, but have tried various ways to write the FileName...)
            FProcess.StartInfo.Arguments = "9e648bbdf5bc3053";
            FProcess.StartInfo.UseShellExecute = false;
            FProcess.Start();
            FProcess.WaitForExit();

With this bit, nothing happens. All the other ways I tried Throws an error. HOw will you Cut up/Use your uninstalString to uninstall that program

The uninstall string is the whole thing, everything after the first executable are arguments, so you need to do something like:

var start_info = new StartInfo() {
    FileName = "rundll32.exe",
    Arguments = "dfshim.dll,ShArpMaintain ItemMan.Client.application, Culture=neutral, PublicKeyToken=4f1069eb693dc232, processorArchitecture=msil",
    UseShellExecute = false
};

Process process = new Process(start_info);

process.Start();
process.WaitForExit();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM