1

shortcut has been created for some windows application like paint under a folder under my documents and all i wanted to do is to invoke these applications with a click event handler of a button. my code as follow:

   Stream myStream = null;
        OpenFileDialog openFileDialog1 = new OpenFileDialog();

        openFileDialog1.InitialDirectory = "c:\\SomeTestFolder";
        //openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
        //openFileDialog1.FilterIndex = 2;
        openFileDialog1.RestoreDirectory = true;

        if (openFileDialog1.ShowDialog() == true)
        {
            try
            {
                if ((myStream = openFileDialog1.OpenFile()) != null)
                {
                    using (myStream)
                    {
                        // Insert code to read the stream here.
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
            }
        }

as you could see this currently open a folder with the short cut on it my question is how do I tweak this to enable me when I click on any short cut an application should launch ? thank you in advance

Sudani
  • 73
  • 8
  • 1
    Use the OpenFileDialog to get the **pathname** of the exe and then pass that to `Process.Start`. – ChrisF Apr 07 '16 at 15:25
  • I'm sorry if you think it is a duplicate. I do believe it is not as I do not want to directly open the path of exe as I mentioned above in my explanation I have created a folder in which I have created a short cut to the exe file within that folder so when I click on openfiledialog I should be able to select the short cut of the exe then select it and click open then the exe should launch. Cause all the Process.Start () launch the exe from it is physical location not through a short cut . Correct if I'm wrong and if my method is not worth trying – Sudani Apr 07 '16 at 22:28
  • I think you are referring to the following code: Process proc = new Proces (); – Sudani Apr 07 '16 at 22:38
  • See this answer for running a shortcut - http://stackoverflow.com/a/23358242/59303 – ChrisF Apr 08 '16 at 07:36
  • this what i have done for those who will come across this post: create variables `//variable that get the windows directory static string windir = Environment.GetEnvironmentVariable("windir"); //variable that point to accessories shortcuts folder static string shortcutsFolder = ConfigurationManager.AppSettings.Get("shortcutFolder"); ` – Sudani Mar 08 '17 at 15:34
  • this what i have done : create variables `//variable that point to accessories shortcuts folder static string shortcutsFolder = ConfigurationManager.AppSettings.Get("shortcutFolder"); ` then on App.config: ` `finally on the button event handler: `private static void btnMovie_Click(object sender, System.Windows.RoutedEventArgs e) { string MovieMaker = shortcutsFolder + "\\MovieMaker"; StartProcess.ProcessMethod(MovieMaker); }` – Sudani Mar 08 '17 at 15:40

0 Answers0