Re: [fpc-pascal] If ShellExecute(0, 'open', PChar(ExecuteName), '', '', 0) = 32 Then

2009-01-29 Thread vmars

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:\LazarusProjectentest
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


Re: [fpc-pascal] If ShellExecute(0, 'open', PChar(ExecuteName), '', '', 0) = 32 Then

2009-01-29 Thread Bart
And now try this withou the use of COMSPEC, and it should work.
The problem is the implicit SW_HIDE (0) you were using.

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


Re: [fpc-pascal] If ShellExecute(0, 'open', PChar(ExecuteName), '', '', 0) = 32 Then

2009-01-28 Thread Henry Vermaak
2009/1/28 vmars vm...@rgv.rr.com:
 I tried many combinations of   %COMSPEC% /c Del2Pas.bat
   ExecuteName := ('C:\\WINDOWS\\system32\\cmd.exe ' + AppPathExe +
 'Del2Pas.bat');
   ExecuteName := ('%COMSPEC%/c Del2Pas.bat');
   and many more!
 but still:

 Unable to open file: %COMSPEC%/c Del2Pas.bat ErrorCode=0

the shell is responsible for resolving environment variables, so you
need to retrieve comspec yourself with GetEnvironmentVariable  in
sysutils.

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


Re: [fpc-pascal] If ShellExecute(0, 'open', PChar(ExecuteName), '', '', 0) = 32 Then

2009-01-28 Thread Bart
 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:\LazarusProjectentest
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


Re: [fpc-pascal] If ShellExecute(0, 'open', PChar(ExecuteName), '', '', 0) = 32 Then

2009-01-27 Thread Bart
Is the problem that you don't see output from del2pas.bat? or is it
not executed at all (and how do you know this)?


If the problem is the first, that may be so because in a .lnk you
specify that the file needs a console, and just running the .bat ma
prevent it frome getting a console?
Put in your del2pas.bat a line like starts a GUI program like
notepad.exe and see if it is launched, that would tell you definitely
if the problem is having assigned a console or not.

(Just a wild guess)

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


Re: [fpc-pascal] If ShellExecute(0, 'open', PChar(ExecuteName), '', '', 0) = 32 Then

2009-01-27 Thread vmars

I tried many combinations of   %COMSPEC% /c Del2Pas.bat
   ExecuteName := ('C:\\WINDOWS\\system32\\cmd.exe ' + AppPathExe 
+ 'Del2Pas.bat');

   ExecuteName := ('%COMSPEC%/c Del2Pas.bat');
   and many more!
but still:

Unable to open file: %COMSPEC%/c Del2Pas.bat ErrorCode=0

Help...

ô¿ô
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: Vinzent Höfler jellyfish.softw...@gmx.net

To: FPC-Pascal users discussions fpc-pascal@lists.freepascal.org
Sent: Monday, January 26, 2009 11:53 PM
Subject: Re: [fpc-pascal] If ShellExecute(0, 'open', PChar(ExecuteName), 
'','', 0) = 32 Then





 Original-Nachricht 

Datum: Mon, 26 Jan 2009 17:42:23 -0600
Von: vmars vm...@rgv.rr.com
An: fpc-pascal@lists.freepascal.org
Betreff: [fpc-pascal] If ShellExecute(0, \'open\', PChar(ExecuteName), 
\'\', \'\', 0)  = 32 Then



Thanks in advance!

[Any ideas why this works:
  ExecuteName := (AppPathExe + 'Del2Pas.bat.lnk');
  ExecuteShell;   ]


[But this doesn't work:
  ExecuteName := (AppPathExe + 'Del2Pas.bat');
  ExecuteShell;
And doesn't give an error msg.]


Just trying an educated guess here, but I suppose .bat-files can only be 
executed via command.com (cmd.exe). Something like %COMSPEC% /c 
Del2Pas.bat could do the trick.



Vinzent.

--
Pt! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: 
http://www.gmx.net/de/go/multimessenger

___
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


Re: [fpc-pascal] If ShellExecute(0, 'open', PChar(ExecuteName), '', '', 0) = 32 Then

2009-01-27 Thread vmars

Wild is good, but same results:

Unable to open file: %COMSPEC%/c Del2Pas.bat ErrorCode=0

ô¿ô
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: Tuesday, January 27, 2009 8:00 AM
Subject: Re: [fpc-pascal] If ShellExecute(0, 'open', PChar(ExecuteName), '', 
'', 0) = 32 Then




Is the problem that you don't see output from del2pas.bat? or is it
not executed at all (and how do you know this)?


If the problem is the first, that may be so because in a .lnk you
specify that the file needs a console, and just running the .bat ma
prevent it frome getting a console?
Put in your del2pas.bat a line like starts a GUI program like
notepad.exe and see if it is launched, that would tell you definitely
if the problem is having assigned a console or not.

(Just a wild guess)

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


Re: [fpc-pascal] If ShellExecute(0, 'open', PChar(ExecuteName), '', '', 0) = 32 Then

2009-01-27 Thread Jonas Maebe


On 28 Jan 2009, at 02:02, vmars wrote:


Wild is good, but same results:

Unable to open file: %COMSPEC%/c Del2Pas.bat ErrorCode=0


You have to resolve %COMSPEC% first (it's an environment variable).


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


[fpc-pascal] If ShellExecute(0, 'open', PChar(ExecuteName), '', '', 0) = 32 Then

2009-01-26 Thread vmars

Thanks in advance!

[Any ideas why this works:
 ExecuteName := (AppPathExe + 'Del2Pas.bat.lnk');
 ExecuteShell;   ]


[But this doesn't work:
 ExecuteName := (AppPathExe + 'Del2Pas.bat');
 ExecuteShell;
And doesn't give an error msg.]


procedure TForm1.ExecuteShell;
begin
//ShowMessage('ExecuteShell = ' + ExecuteName);
   If ShellExecute(0, 'open', PChar(ExecuteName), '', '', 0)  = 32 Then
MessageDlg('Unable to open file: ' + ExecuteName + ' ErrorCode= ' + 
IntToStr(0), mtError,

[mbOk], 0);
end; // procedure TForm1.ExecuteShell




ô¿ô
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) 


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


Re: [fpc-pascal] If ShellExecute(0, 'open', PChar(ExecuteName), '', '', 0) = 32 Then

2009-01-26 Thread Vinzent Höfler

 Original-Nachricht 
 Datum: Mon, 26 Jan 2009 17:42:23 -0600
 Von: vmars vm...@rgv.rr.com
 An: fpc-pascal@lists.freepascal.org
 Betreff: [fpc-pascal] If ShellExecute(0, \'open\', PChar(ExecuteName), \'\', 
 \'\',0)  = 32 Then

 Thanks in advance!
 
 [Any ideas why this works:
   ExecuteName := (AppPathExe + 'Del2Pas.bat.lnk');
   ExecuteShell;   ]
 
 
 [But this doesn't work:
   ExecuteName := (AppPathExe + 'Del2Pas.bat');
   ExecuteShell;
 And doesn't give an error msg.]

Just trying an educated guess here, but I suppose .bat-files can only be 
executed via command.com (cmd.exe). Something like %COMSPEC% /c Del2Pas.bat 
could do the trick.


Vinzent.

-- 
Pt! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: 
http://www.gmx.net/de/go/multimessenger
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal