OK. I finally got there, via much trial and error.

*
ExecuteName := GetEnvironmentVariable('COMSPEC');
{ExecuteName  =   'C:\WINDOWS\system32\cmd.exe'}
ShellExParms := (' /c ' + ExecuteName) ;

If ShellExecute(0, nil, PChar(ExecuteName), PChar(ShellExParms), nil, SW_SHOWNORMAL) <= 32 Then MessageDlg('Unable to open file: ' + ExecuteName + ' ErrorCode= ' + IntToStr(0), mtError,
            [mbOk], 0);
*

Thanks all !

ô¿ô
V  e  r  n

WinXp sp2 , Delphi5, WebDwarf, Trellian WebPage, Lazarus-0.9.26-fpc-2.2.2-win32.exe,
wxPython2.8-win32-unicode-2.8.9.1-py26.exe , Boa 0.6.1
http://www.flickr.com/photos/vmars956/

Wanted: Dwarf Hibiscus (Orange/Rasberry)
----- Original Message ----- From: "Bart" <bartjun...@gmail.com>
To: "FPC-Pascal users discussions" <fpc-pascal@lists.freepascal.org>
Sent: Wednesday, January 28, 2009 4:30 AM
Subject: Re: [fpc-pascal] If ShellExecute(0, 'open', PChar(ExecuteName), '', '', 0) <= 32 Then


Wild is good, but same results:
Unable to open file: "%COMSPEC%/c Del2Pas.bat" ErrorCode=0

Did you try invoking notepad.exe from your batchfile?
I never suggested to use %comspec%.
(And as others pointed out you need to evaluate this with something
like: ComspecStr := GetEnvironmentVariable('COMSPEC') (not tested))

My guess was that the process was executed but was not shown on the
desktop, which lead you to conclude it was never executed.

Ok, the last parameter in ShellExecute determines the way the
application is shown.
You specify 0, that is SW_HIDE, so you will not see the app!
If the batchfile requires interaction from the user you will not see
it and the batchtfile will never terminate.

A returnvalue of 0 from ShellExecute means: The operating system is
out of memory or resources.
For batchfiles (and any other executable) you need not specify 'open',
nil will suffice quite nicely in this case.

There is no need for %comspec% (I'm not even sure it exists in NT
based windows).

Here's my testcase:

procedure TForm1.Button1Click(Sender: TObject);
var
 Res: LongWord;
begin
 Res := ShellExecute(0, nil, PChar('test.bat'),nil,nil,SW_SHOWNORMAL);
 DebugLn('Res = ',DbgS(Res));
end;

Here's the output:

F:\LazarusProjecten>test
Res = 16806

and a new window appears which shows me the output of my test.bat

If I put 0 instead of SW_SHOWNORMAL then I never get to see the output
of my batchfile, but it does run (I can see that because I let it
write to soem file which I examine later).

Tested with Lazarus 0.9.27 rev. 18450 / fpc 2.2.2

Hope this helps.

Bart
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to