일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
- c#
- delphi 10.3
- dbadvgrid
- HTML
- queryset
- MSSQL
- python3
- 중복제거
- Delphi
- Django
- 델파이
- templates
- pyhcarm
- Push
- github
- advColumnGrid
- rank
- get_object_or_404
- python 3.7
- blog
- declare
- 백준
- pythonanywhere
- Visual Studio
- TMS
- PyCharm
- hackerrank
- GIT
- anaconda3
- COMMIT
- Today
- Total
DevHyun
프로세스를 종료시키는 방법 본문
1. kill
private static void killps(string processName)
{
// 프로세스 kill 메소드
Process[] process = Process.GetProcessesByName(processName);
Process currentProcess = Process.GetCurrentProcess();
foreach (Process p in process)
{
if (p.Id != currentProcess.Id)
p.Kill();
}
}
processName은 보통 fom 이름일 경우가 많기 때문에 사용은 아래와 같이 하면 됨.
killps(this.Text);
2. sendmessage
// dll 참조 선언
[DllImportAttribute("User32.dll")]
public static extern int SendMessage(int hwnd, int wMsg, int wParam, int lParam);
[DllImport("user32.dll")]
public static extern int FindWindow(string lpClassName, string lpWindowName);
// 프로세스 kill 명령어
const int Process_Terminate = 0x0010;
// 1) window title로 핸들값 찾기
int myHandle1 = FindWindow(null, windowTitle);
// sendmessage
SendMessage(myHandle1, Process_Terminate, 0, 1);
// 2) 지금 폼의 핸들값을 직접 읽어오기
// 핸들값 변수 선언
public static IntPtr myHandle1;
myHandle1 = this.Handle;
// sendmessage
SendMessage(Convert.ToInt32(myHandle1.ToString()), Process_Terminate, 0, 1);
'C#' 카테고리의 다른 글
Dictionary 활용 (0) | 2023.11.09 |
---|---|
다른 폼 메소드 참조하기 (1) | 2023.11.09 |
클릭 후 드래그로 이동시키기 (0) | 2023.11.09 |
디렉토리 생성 (1) | 2023.11.09 |
ini 파일 읽고 쓰기 (0) | 2023.11.09 |