C#,Delphi,Oracle,MSSQL 개발자블로그
델파이 지정된 프로그램이 실행중인지 체크 본문
1. 개요
특정 프로그램이 실행 중인지 여부를 판단하기 위한 두가지 방법
2. 프로그램 실행 파일명을 이용한 실행여부 판단
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 32 |
uses TlHelp32;
function processExists(exeFileName: string): Boolean; var ContinueLoop: BOOL; FSnapshotHandle: THandle; FProcessEntry32: TProcessEntry32; begin FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); FProcessEntry32.dwSize := SizeOf(FProcessEntry32); ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32); Result := False; while Integer(ContinueLoop) <> 0 do begin if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) = UpperCase(ExeFileName))) then begin Result := True; end; ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32); end; CloseHandle(FSnapshotHandle); end;
procedure TForm1.Button1Click(Sender: TObject); begin if processExists('notepad.exe') then ShowMessage('notepad.exe 실행중!') else ShowMessage('notepad.exe 실행중이지 않음'); end; |
3. 뮤텍스(Mutex)를 이용한 방법
1 2 3 4 5 6 7 |
initialization mHandle := CreateMutex(nil, True, 'myAppIDString'); if GetLastError = ERROR_ALREADY_EXISTS then begin MessageDlg('프로그램이 실행 중입니다.', mtError, [mbOK], 0); Halt; end; |
출처: https://niceit.tistory.com/202 [온달의 IT-World]
'Programming > Delphi' 카테고리의 다른 글
델파이 폼 Maximize, Minimize 버튼 숨기기 (0) | 2019.06.08 |
---|---|
델파이 여러가지 단축키 (0) | 2019.06.08 |
델파이 TButton vs TBitBtn vs TSpeedButton 차이점. (0) | 2018.11.08 |
델파이 EDIT 컴포넌트 숫자만 입력, 오른쪽 정렬 등등 (0) | 2018.11.08 |
델파이 Delphi- 이벤트 실행 순서 (0) | 2018.11.06 |