//(子函数)尾串是否匹配,不分大小写 function AnsiEndsText(const ASubText, AText: string): Boolean; var P: PChar; L, L2: Integer; begin P := PChar(AText); L := Length(ASubText); L2 := Length(AText); Inc(P, L2 - L); if L > L2 then Result := False else Result := CompareString(LOCALE_USER_DEFAULT, NORM_IGNORECASE,P, L, PChar(ASubText), L) = 2; end; var sphandle: DWORD; Found: Bool; PStruct: TProcessEntry32; begin Result := 0; sphandle := createToolhelp32Snapshot($00000002, 0); PStruct.dwSize := Sizeof(PStruct); Found := Process32First(sphandle, PStruct); while Found do begin if AnsiEndsText(ExeName, PStruct.szExefile) then begin Result := PStruct.th32ProcessID; Break; end; Found := Process32Next(sphandle, PStruct); end; CloseHandle(sphandle); end;