|
|
|
내 공부 > 프로그래밍
작성일 : 22-04-06 10:43
|
글쓴이 :
Minuk Y.
 조회 : 901
|
https://kdsoft-zeros.tistory.com/69 [854] |
핵심
* 전연변수로 프로세스 만들고
System.Diagnostics.Process pc;
* 실행파일(경로 및 인자 포함)을 바로 실행하고 프로세스 인스턴스를 변수로 보유
pc = System.Diagnostics.Process.Start(label1.Text);
* 프로세스 죽일 수 있음.
pc.Kill();
---------------------------------------------------------------------------
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;
namespace CSharp_다른응용프로그램실행시키기
{
public partial class Form1 : Form
{
System.Diagnostics.Process pc;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
//exe 파일 필터
ofd.Filter = "EXE File (*.exe) | *.exe";
if (ofd.ShowDialog() == DialogResult.OK)
{
label1.Text = ofd.FileName;
}
}
private void button2_Click(object sender, EventArgs e)
{
//파일이 없으면 종류
if (!System.IO.File.Exists(label1.Text)) return;
//다른 응용 프로그램 실행 시키기...
pc = System.Diagnostics.Process.Start(label1.Text);
}
private void button3_Click(object sender, EventArgs e)
{
// 실행된게 없으면 종료
if (pc == null) return;
//실행 시킨 프로그램 죽이기...
pc.Kill();
}
}
}
|
|
|
|