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?
Sponsored by: â–ˆ Sparkhost - Hosting Without Compromises! â–ˆ Hybrid Performance Web Hosting â–ˆ Spark Host Stream Hosting â–ˆ Hybrid IRC & IRCd Server Shell Accounts
Delphi Question
Started by
TedOb1
, Dec 30 2003 08:44 PM
3 replies to this topic
#1
Posted 30 December 2003 - 08:44 PM
#2
Posted 01 January 2004 - 10:37 AM
Try this
so long ...
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 ...
#3
Posted 02 January 2004 - 09:10 PM
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
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
#4
Posted 07 January 2004 - 03:58 AM
mhhh well, it think it creates a "console" an doesn't close it ...
try instead
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 ...
try instead
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 ...
begin
If ExecAndWait('ping.exe', '127.0.0.1', SW_SHOW) then ShowMessage('pinging finished!');
end;
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users












