Here we will run vlc player. It is my working code
private void launchMeidaPlayer_Click(object sender, EventArgs e)
{
Process[] pname = Process.GetProcessesByName("vlc");
if (pname.Length == 0)
{
try
{
p.StartInfo.UseShellExecute = true;
p.StartInfo.FileName = "vlc.exe";
p.Start();
}
catch (Exception ex) { }
}
else
{
p.Refresh();
WindowHelper.BringProcessToFront(p);
}
}
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DSCP
{
public static class WindowHelper
{
public static void BringProcessToFront(Process process)
{
IntPtr handle = process.MainWindowHandle;
if (IsIconic(handle))
{
ShowWindow(handle, SW_RESTORE);
}
SetForegroundWindow(handle);
}
const int SW_RESTORE = 9;
[System.Runtime.InteropServices.DllImport("User32.dll")]
private static extern bool SetForegroundWindow(IntPtr handle);
[System.Runtime.InteropServices.DllImport("User32.dll")]
private static extern bool ShowWindow(IntPtr handle, int nCmdShow);
[System.Runtime.InteropServices.DllImport("User32.dll")]
private static extern bool IsIconic(IntPtr handle);
}
}
Comments