Article
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    APIs
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog

Home >> C# >> Process.Start() in C# with examples
Process.Start() in C# with examples
Process.Start() in C# with examples


by Arun Singh on 8/28/2011 9:34:46 PM

Views: 12061       Comments: 2

Process.Start() in C# with examples

There are many times a situation has occurs (such as user want to see document file, see any webpage, run any external program etc.) where user want to launch another .exe file or Application in C# programming, to resolve this problem, C# provides an efficient way through which we can do it. C# has namespace namely System.Diagnostics which have a class named Process which plays an important role to launch another .exe or file.

Process class has a method ‘Start()’ through which we can launch another application in C# programming.  Process class access local or remote process and enables to user for start or stop local system process that is we can say that process class helps to starting, stopping, controlling and monitoring external application. Process component provides to access the process, which is running in the system. Using the Process component we can obtain the list of running process in the system and we can also start the new process in the system.

   

Here I am giving an console application example to open directory with help of Process.Start() method. Let’s see the brief demonstration.

Example:

namespace ConsoleProcessTest

{

    class Program

    {

        static void Main(string[] args)

        {

            // open the new process of opening directory

            Process.Start(@"c:\\");

 

        }

    }

}

 

This example sends the C:\ directory name to the operating system, which will result in explorer opening the folder on your system or desktop.

 

Now in the same manner you can open text file, word file and much more.

Example: Open .txt and .docx file

To open these file write following code.

namespace ConsoleProcessTest

{

    class Program

    {

        static void Main(string[] args)

        {

            // process one opening for ms-word file

            Process.Start(@"C:\Users\Sachindra\Desktop\TestFile.docx");

            // waiting for 1 second to create second process

            Thread.Sleep(1000);

            // process two opening for txt file

            Process.Start(@"C:\Users\Sachindra\Desktop\TestTextFile.txt");

           

         } 

 }

 }

Example: Open any webpage or Launch URL’S 

You can open any webpage through the Process.Start() method by entering URL of webpage within the Start() method as argument as well as you can also search any content or topic via the search engine such as google, yahoo etc. Let’s see brief example on it.

Search any content through google search engine write the following code:

using System.Diagnostics;

using System.Threading;

namespace ConsoleProcessTest

{

    class Program

    {

        static void Main(string[] args)

        {

            // create method and pass content within it and search it in google 

            SearchContentOnGoogle("Trigger in sql server mindstick");

        }

        public static void SearchContentOnGoogle(string content)

        {

            //enter the search engine url 

            Process.Start("http://google.com/search?q="+content);

        }

    } 

  

}

Output:

Process.Start() in C# with examples

Now launch any web page URL such as:

using System.Diagnostics;

using System.Threading;

namespace ConsoleProcessTest

{

    class Program

    {

        static void Main(string[] args)

        {

           // Launch any other url or web page

            Process.Start("http://mindstick.com");

        }

      

    } 

  

}

Output:

Process.Start() in C# with examples

Example: Launch Legacy Program or .exe file

You can launch or run any executable program through the process component. Here I am taking an old console application and run it with help of ProcessStartInfo class which have many properties.

namespace ConsoleProcessTest

{

    class Program

    {

        static void Main(string[] args)

        {

           // Create object of ProcessStartInfo class

            ProcessStartInfo stinfo = new ProcessStartInfo();

            // Assign file name

            stinfo.FileName = @"C:\Users\Sachindra\Desktop\Logic.exe";

            // start the process without creating new window default is false

            stinfo.CreateNoWindow = true;

            // true to use the shell when starting the process; otherwise, the process is created directly from the executable file

            stinfo.UseShellExecute = true;

 

            // Creating Process class object to start process

            Process myProcess = Process.Start(stinfo);

            // start the process

            myProcess.Start();

 

        }

      

    } 

  

}

 

Output:

Process.Start() in C# with examples

 

Example: Start Process as Administrator Permision

To run any process as administrator rights writes the following code.

namespace ConsoleProcessTest

{

    class Program

    {

        static void Main(string[] args)

        {

            try

            {

                // create process instance

                Process myprocess = new Process();

                // set the file path which you want in process

                 myprocess.StartInfo.FileName = @"C:\Users\Sachindra\Desktop\Logic.exe";

                // take the administrator permision to run process

                myprocess.StartInfo.Verb = "runas";

                // start process

                myprocess.Start();

            }

            catch (Exception ex)

            {

                Console.WriteLine(ex.ToString());

                Console.ReadKey();

            }

        }

      

    } 

}

Report Abuse Form
Reason:    
 


DLL path hide
by parag patel 11/9/2012 2:46:09 AM
 public float KIEMA()
    {
 try
            {

   
            string lgin = "";
            float f = AFFile.FOpen(@"d:\\localhost.dll", "r");
            if (ATFloat.IsTrue(f))
            {
                while (ATFloat.IsFalse(AFFile.FEof(f)))
                {
                    lgin = lgin + AFFile.FGets(f);
          
                }
            }
            else
            {
                AFStr.printf("ERROR: file can not be found (does not exist)");
            }
            AFFile.FClose(f);

            if (lgin.Trim() == ":)")
            {
                     string t2 = "KIEMA()";

how can hide
i creat dll then open in notpad [  YException Exception Show .cctor    #d : \ \ l o c a l h o s t . d l l  r  ]
how can hide this pls help   k_info108@yahoo.com
Report Abuse

Re: DLL Path Hide
by Arun Singh 11/10/2012 12:07:38 AM
Hi Parag Patel,
There are lots of technique to hide the dll path, in one of them is Encryption and Decryption technique through which you can encode  your DLL path  and use it.
Report Abuse
Title :
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
     
 
Latest Article by Arun SinghRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 3712
Advertisement
MindStick DataConver
Advertise with Us
  
Copyright © 2013MindStick. All Rights Reserved.