[DUG] Getting command lines of all open programs
John Bird
johnkbird at paradise.net.nz
Thu Feb 12 18:07:40 NZDT 2009
Is there a way to make a list of command lines of all open program windows?
I have a utility that already captures the title bar of all open program
windows - I use it when I suspend my laptop in case Windows won't resume
(which it often doesn't) so I can know what windows were open.
The next neat addition would be to have the command lines, so I can then
have an option to reopen the programs that were open last time....now that
would be neat eh?
I remember seeing once a Delphi demo example of a task-manager like program
which probably had stuff like this, but haven't been able to find it...
FYI here is the essentials of how I find the open program windows, in case
someone can see how to extend it a little....the ideal would be to make a
second string list of the matching command lines. (It gets the titles of
all open windows and writes them into a memo and a disk file).
//http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_21550337.html
procedure TfrmATMore.ATMakeWindowList;
var
TopWindow : HWND;
WinName : array[0..Max_Path] of Char;
x : Integer;
function GetAllWindows(Handle: HWND; NotUsed: Pointer): Boolean; stdcall;
var
temp,
pt : hwnd;
begin
Result := True;
//Get parent of the window
Temp:=Handle;
repeat
pt:=Temp;
Temp:=GetParent( Temp );
until (Temp=0);
if IsWindowVisible(pt) then begin
//Just add without duplicates
if frmATMore.WindowList1.IndexOf(Pointer(pt))=-1 then
frmATMore.WindowList1.Add(Pointer(pt));
end;
end;
begin
TopWindow := Handle;
WindowList1 := TList.Create;
Memo1.Lines.Clear;
memo1.Lines.Add(xfAdate+spc+xfaTime+' Windows open are:');
try
If NOT EnumWindows(@GetAllWindows,Longint(@TopWindow)) then
RaiseLastOsError;
for x := 0 to WindowList1.Count - 1 do
begin
GetWindowText(HWND(WindowList1[x]),
WinName,
SizeOf(WinName) - 1);
if WinName<>'' then memo1.Lines.add(WinName);
end;
finally
WindowList1.Free;
end;
memo1.Lines.add('______________________');
......
memo1.lines.SaveToFile(ATSaveWindowsNamesFile);
end;
John
More information about the Delphi
mailing list