Saturday, October 24, 2009

Loading applications code sample

Code snippet for loading applications (This was adapted from a tutorial over at CodeProject so not even going to claim that I was the first to do this :) It's just a function I've used a few times at home). I'll be expanding it to take in a FileName as a string that will be the file I want to load, but I'm a keep it simple kind of girl. Do the basics first, get that bedded down, then add in more complexity. This is for windows apps/ console apps.

FileName is the location of the executable I want to load
i.e. FileName = @"C:\Program Files\Mobipocket.com\Mobipocket Reader\reader.exe";


 private void loadApplication(string FileName)
        {
            Process p = null;
            try
            {
                p = new Process();
                p.StartInfo.FileName = FileName;
                p.Start();
                p.WaitForExit();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception Occurred :{0},{1}",
                         ex.Message, ex.StackTrace.ToString());
            }

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.