Executing a string as a command

Hi,

I have read a string from some key in the registry, this string contains a command which should run to uninstall something....   how do i execute the command which i have found in the registry(i have written this command into a string)?

Thank You.
JetixilAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Gautham JanardhanConnect With a Mentor Commented:

Microsoft.Win32.RegistryKey Fregistry =
                Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE")
                .OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion")
                .OpenSubKey("Installer").OpenSubKey("UserData")
                .OpenSubKey("S-1-5-18").OpenSubKey("Products");
            string []Names = Fregistry.GetSubKeyNames() ;
            string uninstall = "";
            string ApplicationName = "Adobe Reader 7.0.8";
            for (int i = 0; i < Names.Length; i++)
            {
                Microsoft.Win32.RegistryKey FTemp = Fregistry.OpenSubKey(Names[i]).OpenSubKey("InstallProperties");
                if (FTemp.GetValue("DisplayName").ToString() == ApplicationName)
                {
                    object obj = FTemp.GetValue("UninstallString");
                    if (obj == null)
                        uninstall = "";
                    else
                        uninstall = obj.ToString();
                    i = Names.Length; 
                }
            }
 
            System.Console.WriteLine(uninstall);
            System.Diagnostics.Process FProcess = new System.Diagnostics.Process();
            string temp = "/x{" + uninstall.Split("/".ToCharArray())[1].Split("I{".ToCharArray())[2];
            //replacing with /x with /i would cause another popup of the application uninstall
            FProcess.StartInfo.FileName = uninstall.Split("/".ToCharArray())[0];
            FProcess.StartInfo.Arguments = temp;
            FProcess.StartInfo.UseShellExecute = false;
            FProcess.Start();
            System.Console.Read();

Open in new window

0
 
kirankumar_gouraCommented:
You can use Process.Start method in the namespace System.Diagnostics to achieve this functionality.
For example if your string is something like
String str = "Application.exe /u";
then split it using String[] strings = str.Split(' ')
and the execute with the following statement
Process.Start(strings[0], strings[1]);

Let me know for further assistance.

0
All Courses

From novice to tech pro — start learning today.