掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
起動しているアプリケーションを調べるには (ID:11248)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
起動プロセスIDやパスを得る方法です。 プロセスIDからハンドルを求めるのはわかりません。 Windowを列挙してプロセスIDとの一致を求めたらいいのかな? type TProcessItem = class(TObject) ID: Cardinal; Name: String; Path: String; end; function GetWindowsDirectory: string; var Buffer:array [0..MAX_PATH-1] of Char; begin Windows.GetWindowsDirectory(Buffer,MAX_PATH); Result:=StrPas(Buffer); end; function TranslateFilename(SourceFileName: String): String; begin Result := SourceFileName; Result := StringReplace(Result, '\SystemRoot', GetWindowsDirectory, []); Result := StringReplace(Result, '\??\', '', []); end; procedure GetProcExeNameList(Dest: TObjectList); var hProcessSnapshot: THandle; ProcessEntry: TProcessEntry32; PID: Cardinal; ProcessStatus: Boolean; hProcess: THandle; ModuleFileName: array[0..MAX_PATH] of Char; Item: TProcessItem; begin Dest.Clear; hProcessSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if hProcessSnapshot <> $FFFFFFFF then begin try ProcessStatus := Process32First(hProcessSnapshot, ProcessEntry); while ProcessStatus do begin PID := ProcessEntry.th32ProcessID; hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, PID); if hProcess <> 0 then begin Item := TProcessItem.Create; Item.ID := PID; Item.Name := ProcessEntry.szExeFile; try if GetModuleFileNameEx(hProcess, 0, ModuleFileName, Sizeof(ModuleFileName)) = 0 then begin Item.Path := '[System]'; end else begin Item.Path := TranslateFilename(ModuleFileName); end; Dest.Add(Item); finally CloseHandle(hProcess); end; end; ProcessStatus := Process32Next(hProcessSnapshot, ProcessEntry) end finally CloseHandle(hProcessSnapshot); end; end else raise Exception.Create(SysErrorMessage(GetLastError)); end;
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.