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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Gautham JanardhanCommented:

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.