December 31st, 2003, 04:57 AM
shellexec in delphi
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 remotly. 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:
Memo1.Lines.SetText('Please Wait While Prosess Info is Gathered.');
ShellExecute(Handle, 'open', PChar('cmd.exe'), PChar('/C PSlist.exe -t \\'+Edit1.Text + ' >Plist.txt'), Nil, SW_HIDE);
(the default edit1.text property is set for 127.0.0.1)
ExecuteFile, ParamString, StartInString: string;
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);
ParamString can contain the
lpParameters := PChar(ParamString);
StartInString specifies the
name of the working directory.
If ommited, the current directory is used.
// lpDirectory := PChar(StartInString);
nShow := SW_SHOWNORMAL;
if ShellExecuteEx(@SEInfo) then begin
until (ExitCode <> STILL_ACTIVE) or
else ShowMessage('Error starting Program')
waits for the program to complete before returning.
using the first method is there a way to make it wait -or- using the second method is there a way to redirect the output?
Bukhari:V3B48N826 “The Prophet said, ‘Isn’t the witness of a woman equal to half of that of a man?’ The women said, ‘Yes.’ He said, ‘This is because of the deficiency of a woman’s mind.’”