In this article we will see how we can call windows exe from Windows Application or any 3rd Party Installed Software on a Button Click
Introduction
Hello Friends,
Today in this article we will see how we can access windows operating system exe's and any installed S/W in the PC.
In this article we will be accessing
Windows EXE
- Notepad
- Windows Media Player
- Sound Recorder
3rd Party Apps
- MS Word
- Irfan View (Free Ware Software)
- MS Excel
Objective
Understanding how does the Shell Command of VB.NET works in C Sharp.
In VB.NET to open any Installed application we used Shell Command but in C Sharp the Shell Command does not work for that we use a Reference provided i.e. System.Diagnostics and using it Process.Start Method.
Using the code
The Process.Start Method of the System.Diagnostic Library allows us to run the exe's installed in the PC.
It works well for any Apps even any 3 rd Party Software.
The Process.Start requires the Path where the exe is placed in the computer as a Parameter.
// Code Behind
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace Shell_Application
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnNotepad_Click(object sender, EventArgs e)
{
try
{
Process.Start(@"C:\Windows\system32\notepad.exe");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnWindowsMediaPlayer_Click(object sender, EventArgs e)
{
try
{
Process.Start(@"C:\Program Files\Windows Media Player\wmplayer.exe");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnSoundRecorder_Click(object sender, EventArgs e)
{
try
{
Process.Start(@"C:\Windows\system32\SoundRecorder.exe");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnMSWord_Click(object sender, EventArgs e)
{
try
{
Process.Start(@"C:\Program Files\Microsoft Office\Office12\WINWORD.EXE");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnExcel_Click(object sender, EventArgs e)
{
try
{
Process.Start(@"C:\Program Files\Microsoft Office\Office12\EXCEL.EXE");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnOpenIrfanView_Click(object sender, EventArgs e)
{
try
{
Process.Start(@"C:\Program Files\IrfanView\i_view32.exe");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
Output Screen
On each Button Click it will open the associated Exe's
Output for Opening MS Excel
Excel Launch
Hope this will be useful