[Delphi] Aktives Fenster/Programm ermitteln

08/05/2010 18:58 マルコ#1
Hi ihrs,
ich weiß, nur wenige benutzen diese Sprache (auch wenn ich sie super finde^^). Aber vllt kennt sich dennoch wer damit n bisl aus.

Mein Problem:
Ich programier grad einen Passwort Manager. Der 1. Teil (Also der Anmeldeteil für den Manager und der Kryptographoie-Teil für die Passwörter) ist fertig. Nun soll der Manager aber auch noch das richtige Passwort in ein Programm einfügen. Der Benutzer muss zuerst den Exe-Namen des Programms mit seinen Login-Daten eingeben. Damit kann ich überprüfen, welches Programm der eingegebenen Programme gerade läuft. Nun brauch ich aber insofern hilfe, da ich keine Ahnung hab, wie das Programm ermitteln kann, ob das jeweilige Programm auch aktiv ist (so dass es die Daten eingeben kann). Außerdem kann man ja auch mehrere Programme starten, die in der Tabelle aufgeführt sind. Das Programm muss also den richtigen Eintrag raussuchen. Nur WIE mach ich das...(Ich hab schon bei Google gesucht, aber nichts gefunden, das passen würde)
Das ist eigentlich sogar das letzte Puzzleteil, das noch fehlt. Das Programm schreibt per globalem Hotkey die eingegebenen Daten in das aktive Programm.

So, damit ihr euch auchnoch n bild machn könnt, wie das aussieht:
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]
08/05/2010 19:40 HardCore.1337#2
Code:
function CheckProgIsRunnig (AppName : String) : Boolean;
var
  i : Integer;
  pidNeeded : DWORD;
  PIDList : array[0..1000] of Integer; 
  PIDName : array [0..MAX_PATH - 1] of char;
  PH : THandle;
  re : Boolean;
  AppCnt : Byte;
begin
AppCnt := 0;
re := False;

if not Psapi.EnumProcesses(@PIDList, 1000, pidNeeded) then
exit;

for i := 0 to (pidNeeded div sizeof (Integer)- 1) do
begin<BR>
PH := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,
False, PIDList[i]);
if PH <> 0 then
begin
if Psapi.GetModuleBaseName(PH, 0, PIDName, sizeof (PIDName)) > 0 then
begin
if UpperCase(StrPas(PIDName)) = AppName then Inc(AppCnt);
// ListBox1.Items.Add('process : ' + PIDName);
CloseHandle(PH);
end;
end;
end;
if AppCnt > 1 then Re := True;
Result := re;
end;

...

Procedure TForm1.Button1Click(Sender ....);
  if CheckProgIsRunnig ('PROJECT1.EXE') = True then begin 
end;<BR>
end;<BR>
Quelle: [Only registered and activated users can see links. Click Here To Register...]
08/05/2010 20:06 マルコ#3
dankääää^^
Jezz kann ich das Teil endlich fertig stellen!

Edit: Nee, geht auch nich. Zumindest nicht mit dem Exe Namen. Ich hab sogar die von Andreas (in dem Entwicklerforum) vorgeschlagene Veränderung vorgenommen. Aber er erkennt nicht, dass Notepad.exe aktiv ist. Schade eigentlich...
08/05/2010 21:02 Krez#4
[Only registered and activated users can see links. Click Here To Register...]
08/07/2010 12:15 マルコ#5
Quote:
Originally Posted by minecrawler
MarGet, I think you are English , so I answer in English oO

1st : This Unit is buggy. But when I used the Version from the comments (that still had bugs -.-) and corrected it (inserted <>, so no problem at all^^), it worked. It indeed said that notepad was running. But it also said that it's running even though it's not active. Right at the moment, Mozilla Firefox is active. If I press the hotkeys, it sais notepad is running. What I need is a function that tells me, if a program (for example notepad.exe , but can be anything else) is activ at the moment. Maybe you used Google translator and didn't get the problem.
This is a password manager. It should insert the right password for an application when you press a hotkey. But the program has to find out which program is active, so into what program it enters the username and the password. This way, you can open a lot of programs which you entered into the list and the program only inserts the data for the right application.
btw, the following function is much easier for finding out, if a program is running:
Code:
function IsExeRunning(const AExeName: string): boolean;
var
  h: THandle;
  p: TProcessEntry32;
begin
  Result := False;

  p.dwSize := SizeOf(p);
  h := CreateToolHelp32Snapshot(TH32CS_SnapProcess, 0);
  try
    Process32First(h, p);
    repeat
      Result := AnsiUpperCase(AExeName) = AnsiUpperCase(p.szExeFile);
    until Result or (not Process32Next(h, p));
  finally
    CloseHandle(h);
  end;
end;
Leute, das Problem ist noch nicht gelöst...mit der Funktion kann man zwar sagen, dass ein Programm läuft, aber nicht, ob es aktiv ist, oder nicht! Hier muss es doch irgendwen gebn, der weiß, wie das geht (von mir aus auch ne Funktion in C/C++ !)