hacking contest

hacking exploits security forum
hacking
compliance articles
upgrade backup exec
information security consultant

Full Version: Delphi Question
TedOb1
recently i got a hold of a copy of delphi7. having to take a pragmatic approch to learning anything i decided that makeing a front end for "something" would be a good place to start.

so 'using SHELLAPI', fport and a few of the pstools i develped a gui that will list or kill processes locally and remotly, open a remote shell, uses fport to map open ports to apps, will ping a host and start a program on a remote machine. i know....big friggen deal, but for me it's a good way to learn.

now when i use shellexec to run a dos type app it works fine unless it takes lorger than normal for the called app to run. since i redirect the output to a text file and use it as a source for a memo box, if the program hasn't finished i get a "can not open" such and such a file name error. Which has not been a problem on the local network but is accross a vpn where things take a little longer

i use 2 methods.the first will shell out to dos, sleep for 4 seconds then load the returned info to memo1:

begin

Memo1.Lines.SetText('Please Wait While Prosess Info is Gathered.');
Memo1.Refresh ;
ShellExecute(Handle, 'open', PChar('cmd.exe'), PChar('/C PSlist.exe -t \\'+Edit1.Text + ' >Plist.txt'), Nil, SW_HIDE);
Sleep(4000);
Memo1.Lines.LoadFromFile('Plist.txt');
Memo1.SetFocus ;

end;

(the default edit1.text property is set for 127.0.0.1)

the second:

var
SEInfo: TShellExecuteInfo;
ExitCode: DWORD;
ExecuteFile, ParamString, StartInString: string;
begin
ExecuteFile:='cmd.exe ';
ParamString:= '/k PSexec '+ Edit1.Text + ' -s cmd';

FillChar(SEInfo, SizeOf(SEInfo), 0);
SEInfo.cbSize := SizeOf(TShellExecuteInfo);
with SEInfo do begin
fMask := SEE_MASK_NOCLOSEPROCESS;
Wnd := Application.Handle;
lpFile := PChar(ExecuteFile);
lpParameters := PChar(ParamString);
nShow := SW_SHOWNORMAL;
end;
if ShellExecuteEx(@SEInfo) then begin
repeat
Application.ProcessMessages;
GetExitCodeProcess(SEInfo.hProcess, ExitCode);
until (ExitCode <> STILL_ACTIVE) or
Application.Terminated;
ShowMessage('Done!');
end
else ShowMessage('Error starting Program')

end;


wait for the program to complete before returning.

using the first method is there a way to make it wait for the app to finish or using the second method is there a way to redirect it's output?
temptation
Try this

CODE
uses WinTypes, WinProcs, SysUtils;

 function ExecAndWait(const Filename, Params: string; WindowState: word): boolean;
 var SUInfo: TStartupInfo;
     ProcInfo: TProcessInformation;
     CmdLine: string;
 begin
   CmdLine := '"' + Filename + '"' + Params;
   FillChar(SUInfo, SizeOf(SUInfo), #0);
   with SUInfo do begin
     cb := SizeOf(SUInfo);
     dwFlags := STARTF_USESHOWWINDOW;
     wShowWindow := WindowState;
   end;
   Result := CreateProcess(NIL, PChar(CmdLine), NIL, NIL, FALSE,
                           CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, NIL,
                           PChar(ExtractFilePath(Filename)),
                           SUInfo, ProcInfo);
   if Result then WaitForSingleObject(ProcInfo.hProcess, INFINITE);


so long ...
TedOb1
thank for replying temptation.

when i test it by putting this in a tbutton nothing happens...no errors though

begin
ExecAndWait( 'cmd.exe', ' /k ping 63.770.62.67 ', 1);
end;

tryed double quotes around cmd.exe

tryed it without adding ping

temptation
mhhh well, it think it creates a "console" an doesn't close it ...

try instead
CODE

begin
 ExecAndWait('ping.exe', '127.0.0.1', SW_SHOW);
end;


Anyway ...
do you know what a "function" is ?
ExecAndWait('ping.exe', '127.0.0.1', SW_SHOW);
^^ This would be a simple procedure ...

Do it like ...
CODE

begin
 If ExecAndWait('ping.exe', '127.0.0.1', SW_SHOW) then ShowMessage('pinging finished!');
end;
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.

 
Invision Power Board © 2001-2005 Invision Power Services, Inc.