Autor Beitrag
Harry M.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 754

Win 2000, XP
D2005
BeitragVerfasst: Sa 29.01.05 22:40 
wie kann ich fest stellen, aus welchem verzeichnis das programm xy gestarte wurde?

gruß
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Sa 29.01.05 22:43 
Den Namen der Exe bekommt man mit Application.ExeName; Das aktuelle Verzeichnis erhält man mit GetCurrentDir;

_________________
We are, we were and will not be.
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 29.01.05 22:44 
Ganz einfach:

In der Variable ParamStr(0) ist der Programmpfad plus Name der Anwendung gespeichert. Zum Extrahieren der Pfadangaben einfach die Funktion ExtractFileDir verwenden.

Insgesamt sieht das dann so aus:

ausblenden Delphi-Quelltext
1:
2:
var pfad: String;
pfad := ExtractFileDir(ParamStr(0));

Achtung: Der Pfad hat hinten KEINEN Backslash. Der ist vielleicht ab un zu nötig. Kann man aber auch einfach dazumachen:

ausblenden Delphi-Quelltext
1:
2:
var pfad: String;
pfad := ExtractFileDir(ParamStr(0))+'\';

;)

_________________
Steht der Bauer im Gemüse, hat er später grüne Füße.
Harry M. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 754

Win 2000, XP
D2005
BeitragVerfasst: Sa 29.01.05 23:16 
danke für die antworten, aber das meine ich nicht. ich möchte mit meinem programm den phat ermitteln aus dem das programm yx gestarte wurde (nicht meine eigenen ausführungspath) xy.exe = c:\test\xy.exe also den path anderer programme festellen.
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: So 30.01.05 00:13 
Na dann muss du das Programm einfach suchen und als Ergebnis bekommst du den Pfad zu der Datei.

Also z.B.:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(ExtractFileDir(FileSearch('cmd.exe', 'C:\WINXP\system32')));
end;

Interessant auch das Beispiel aus der Delphi-Hilfe:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure TForm1.Button1Click(Sender: TObject);

var
  buffer: array [0..255] of char;
  FileToFind: string;
begin
  GetWindowsDirectory(buffer, SizeOf(buffer));
  FileToFind := FileSearch(Edit1.Text, GetCurrentDir + ';' + buffer);
  if FileToFind = '' then
    ShowMessage('Couldn''t find ' + Edit1.Text + '.')
  else
    ShowMessage('Found ' + FileToFind + '.');

end;

_________________
Steht der Bauer im Gemüse, hat er später grüne Füße.
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: So 30.01.05 01:51 
User-Xy2004 hat folgendes geschrieben:
wie kann ich fest stellen, aus welchem verzeichnis das programm xy gestarte wurde?

Vorher weißt du denn, das Programm xy überhaupt gestartet worden ist?

Es gibt halt verschiedene Möglichkeiten dieses zu ermitteln.

_________________
Ciao, Sprint.
Harry M. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 754

Win 2000, XP
D2005
BeitragVerfasst: So 30.01.05 01:58 
beide antorten führen nleider nicht zum erfolg. ähnlich wie beim norton prozessview falls du den kennst

also ich bastele grad an einem tool welches die laufenden prozesse auf einem rechner überwacht.
so wie eine firewall. so ähnlich habe ich auch mein prog aufgebaut. mein programm bemerkt jetzt das der prozess cmd.exe gestartet wurde. es soll jetzt feststellen ob es auch im verzeichnis %SYSTEMROOT%\system32 gestart wurde und falls nicht eine warnung ausgeben.

gruß


Zuletzt bearbeitet von Harry M. am So 30.01.05 02:07, insgesamt 1-mal bearbeitet
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: So 30.01.05 02:05 
User-Xy2004 hat folgendes geschrieben:
beide antorten führen nleider nicht zum erfolg. ähnlich wie beim norton prozessview falls du den kennst

Antworte auf meine Frage, dann sage ich dir den Lösungsweg.

_________________
Ciao, Sprint.
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: So 30.01.05 02:40 
Dann hast du also die ProcessId von dem Prozess. Nun kannst du dir z.B. mit OpenProcess ein ProcessHandle holen und mit GetModuleFileNameEx den vollständigen Pfad mit Dateinamen ermitteln. ExtractFilePath gibt dann den gewünschten Pfad zurück.

ausblenden Delphi-Quelltext
1:
uses PSAPI;					

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
var
  ProcessHandle: THandle;
  S: String;
begin

  ProcessHandle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, ProcessId);
  if ProcessHandle <> 0 then
  begin
    SetLength(S, MAX_PATH);
    SetLength(S, GetModuleFileNameEx(ProcessHandle, 0, PChar(S), Length(S)));
    ShowMessage(ExtractFilePath(S));
    CloseHandle(ProcessHandle);
  end;

end;


Das ist ein Weg. Gibt halt noch mehrere.

_________________
Ciao, Sprint.
Harry M. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 754

Win 2000, XP
D2005
BeitragVerfasst: So 30.01.05 19:45 
wäre schön wenn du mir noch mehr wege zeigen könntes. ich habe nur den namen des processes

ich hänge dir mal den code an den ich verwende

ausblenden Delphi-Quelltext
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:
function GetProcessID(sProcName: String): Integer; 
var 
  hProcSnap: THandle; 
  pe32: TProcessEntry32; 
begin 
  result := -1; 
  hProcSnap := CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, 0); 
  if hProcSnap = INVALID_HANDLE_VALUE then exit; 

  pe32.dwSize := SizeOf(ProcessEntry32); 

  { wenn es geklappt hat } 
  if Process32First(hProcSnap, pe32) = true then 
    { und los geht's: Prozess suchen} 
    while Process32Next(hProcSnap, pe32) = true do 
    begin 
      if pos(sProcName, pe32.szExeFile) <> 0then 
        result := pe32.th32ProcessID; 
    end; 
  CloseHandle(hProcSnap); 
end; 

procedure TMain1.Timer1Timer(Sender: TObject);
begin
  Listbox1.Clear;
  GetProcessList(Listbox1.Items);
  // weitere anweisungen die zwische zulässigen und unzulässigen filtern (wurde voher konfiguriet)
end;


leider bekomme ich da keine PID

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt.
wulfskin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1349
Erhaltene Danke: 1

Win XP
D5 Pers (SSL), D2005 Pro, C, C#
BeitragVerfasst: So 30.01.05 19:50 
Nur so nebenbei: Luckie hat dazu auch ein schönes Programm geschrieben (dessen Name ich gerade vergessen habe). Wenn du ein bisschen auf seiner Homepage stöberst, findest du es bestimmt.

Gruß Hape!

_________________
Manche antworten um ihren Beitragszähler zu erhöhen, andere um zu Helfen.
Harry M. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 754

Win 2000, XP
D2005
BeitragVerfasst: So 30.01.05 19:51 
gehe ich doch gleich mal kucken...
Harry M. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 754

Win 2000, XP
D2005
BeitragVerfasst: So 30.01.05 20:08 
ich bin fündig geworden....

danke nochmals für die antworten