ये अगर डेल्फी XE2
चल रहा है निर्धारित करने के लिए कदम उठाए जाते हैं
1) सबसे पहले पढ़ें \Software\Embarcadero\BDS\9.0
रजिस्ट्री कुंजी जो में स्थित किया जा सकता है में App
प्रविष्टि से bds.exe फ़ाइल का स्थान HKEY_CURRENT_USER या HKEY_LOCAL_MACHINE रूट कुंजी।
2) फिर CreateToolhelp32Snapshot फ़ंक्शन का उपयोग करके आप जांच सकते हैं कि एक ही नाम के साथ एक exe मौजूद है या नहीं।
3) अंत में अंतिम संसाधित प्रविष्टि के पीआईडी का उपयोग करके आप एक्स के पूर्ण फ़ाइल पथ को हल कर सकते हैं (GetModuleFileNameEx
फ़ंक्शन का उपयोग करके) और फिर नामों की तुलना करें।
चेक इस नमूना कोड
{$APPTYPE CONSOLE}
{$R *.res}
uses
Registry,
PsAPI,
TlHelp32,
Windows,
SysUtils;
function ProcessFileName(dwProcessId: DWORD): string;
var
hModule: Cardinal;
begin
Result := '';
hModule := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, dwProcessId);
if hModule <> 0 then
try
SetLength(Result, MAX_PATH);
if GetModuleFileNameEx(hModule, 0, PChar(Result), MAX_PATH) > 0 then
SetLength(Result, StrLen(PChar(Result)))
else
Result := '';
finally
CloseHandle(hModule);
end;
end;
function IsAppRunning(const FileName: string): boolean;
var
hSnapshot : Cardinal;
EntryParentProc: TProcessEntry32;
begin
Result := False;
hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if hSnapshot = INVALID_HANDLE_VALUE then
exit;
try
EntryParentProc.dwSize := SizeOf(EntryParentProc);
if Process32First(hSnapshot, EntryParentProc) then
repeat
if CompareText(ExtractFileName(FileName), EntryParentProc.szExeFile) = 0 then
if CompareText(ProcessFileName(EntryParentProc.th32ProcessID), FileName) = 0 then
begin
Result := True;
break;
end;
until not Process32Next(hSnapshot, EntryParentProc);
finally
CloseHandle(hSnapshot);
end;
end;
function RegReadStr(const RegPath, RegValue: string; var Str: string;
const RootKey: HKEY): boolean;
var
Reg: TRegistry;
begin
try
Reg := TRegistry.Create;
try
Reg.RootKey := RootKey;
Result := Reg.OpenKey(RegPath, True);
if Result then
Str := Reg.ReadString(RegValue);
finally
Reg.Free;
end;
except
Result := False;
end;
end;
function RegKeyExists(const RegPath: string; const RootKey: HKEY): boolean;
var
Reg: TRegistry;
begin
try
Reg := TRegistry.Create;
try
Reg.RootKey := RootKey;
Result := Reg.KeyExists(RegPath);
finally
Reg.Free;
end;
except
Result := False;
end;
end;
function GetDelphiXE2LocationExeName: string;
Const
Key = '\Software\Embarcadero\BDS\9.0';
begin
Result:='';
if RegKeyExists(Key, HKEY_CURRENT_USER) then
begin
RegReadStr(Key, 'App', Result, HKEY_CURRENT_USER);
exit;
end;
if RegKeyExists(Key, HKEY_LOCAL_MACHINE) then
RegReadStr(Key, 'App', Result, HKEY_LOCAL_MACHINE);
end;
Var
Bds : String;
begin
try
Bds:=GetDelphiXE2LocationExeName;
if Bds<>'' then
begin
if IsAppRunning(Bds) then
Writeln('The Delphi XE2 IDE Is running')
else
Writeln('The Delphi XE2 IDE Is not running')
end
else
Writeln('The Delphi XE2 IDE Is was not found');
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
Readln;
end.
addtional संसाधनों। Detecting installed delphi versions
यदि आप मुख्य विंडो के विंडो हैंडल को पा सकते हैं तो आप प्रक्रिया आईडी प्राप्त करने के लिए GetWindowThreadProcessId का उपयोग कर सकते हैं। फिर प्रक्रिया संभाल पाने के लिए ओपनप्रोसेस को कॉल करें। फिर exe फ़ाइल नाम को पकड़ने के लिए GetModuleFileNameEx पर कॉल करें। फिर exe फ़ाइल के संस्करण संसाधन को पढ़ने के लिए GetFileVersionInfo आदि का उपयोग करें। ओह! –
@ डेविड हेफरन: :-) फिर से, और फिर एक गहरी सांस लें। वहां बेहतर महसूस करना चाहिए। –
मुझे उम्मीद है कि उपर्युक्त नौकरी करेगा लेकिन अगर कोई आसान तरीका ढूंढ सकता है तो मैं कम से कम आश्चर्यचकित नहीं होगा। –