C# API WinExec () fonksiyonu

Posted: July 6, 2014 in C#
Tags: ,

Bilgisayarda kurulu olan herhangi bir programı calıstırmak icin kullanılan fonksiyondur.

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.Runtime.InteropServices;

namespace WindowsFormsApplication13
{
public partial class Form1 : Form
{

[DllImport(“kernel32”)]
public static extern long WinExec(string IpCmdLine ,int nCmdShow);
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}
private void button1_Click(object sender, EventArgs e)
{

long Sonuc = WinExec(“C:\\Windows\\System32\\Notepad.exe”, 9);

}

}
}

ikinci parametre olarak verilen sayı calıstırılan programın boyutu icin önemlidir.

3 olursa-> Programa ait pencere ekranı kaplar
6 olursa->simge durumuna kücültülür.
9 olursa-> orjinal boyutlarıyla kalır.

Bilgisayarda kurulu programları calıstırırken System.Diagnostics adlı namespace deki Process sınıfından yararlanabiliriz.

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.Runtime.InteropServices;
using System.Diagnostics;

namespace WindowsFormsApplication13
{
public partial class Form1 : Form
{

[DllImport(“kernel32”)]
public static extern long WinExec(string IpCmdLine ,int nCmdShow);
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}
private void button1_Click(object sender, EventArgs e)
{

string git = “C:\\Program Files\\Microsoft Games\\Chess\\Chess.exe”;
System.Diagnostics.Process İslem;
İslem = new System.Diagnostics.Process();
İslem.StartInfo.FileName = git;
İslem.Start();

}

}
}

chess oyunu

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s