Wednesday 22 August 2018

C#: Process class

Process class provides access to local and system processes. Process class exist in 'System.Diagnostics' namespace, by using Process class, you can open a url, any executable.

Open a File path in windows explorer
Process.Start("c:\\");   : Opens C drive in windows explorer

Process.Start("C:\\Users"); : opens C:\\users in windows explorer

Program.cs
using System.Diagnostics;

class Program
{
    static void Main()
    {
        Process.Start("c:\\");

        Process.Start("C:\\Users");
    }

}

Open Applications
Process.Start("notepad"); : Opens notepad

Process.Start("wordpad"); : Opens wordpad

Process.Start("notepad++");   : Opens notepad++

Program.cs
using System.Diagnostics;

class Program
{
    static void Main()
    {
        Process.Start("notepad");

        Process.Start("wordpad");

        Process.Start("notepad++");
    }

}


Open files
Process.Start(@"C:\Users\Documents\Study\C#\Miscellaneous.docx"); : Open Miscellaneous.docx file


Program.cs
using System.Diagnostics;

class Program
{
    static void Main()
    {
        Process.Start(@"C:\Users\Documentabs\Study\C#\Miscellaneous.docx");
    }

}

Opens an URL
Process.Start(@"https://self-learning-java-tutorial.blogspot.com");

Above statement opens my web site home page.


Program.cs
using System.Diagnostics;

class Program
{
    static void Main()
    {
        Process.Start(@"https://self-learning-java-tutorial.blogspot.com");
    }

}



Previous                                                 Next                                                 Home

No comments:

Post a Comment