Link to home
Start Free TrialLog in
Avatar of Dark_King
Dark_King

asked on

ShellExecute

Need help with this.

I use ShellExecute to start a .bat file and want to pass variable to it.
Variables is given from dos when I start the program.
It look like this.
ShellExecute(I, 'open', 'c:\command.com', PChar('/c  s:\public\homch2.bat '+ ParamStr(1) + ParamStr(2)), nil,  sw_hide);

In the bat file it look like this.
renobj %1 %2

Is it the wrong way or wath ????
Avatar of Epsylon
Epsylon

Try

ShellExecute(I, 'open', PChar('s:\public\homch2.bat '+ ParamStr(1) + ParamStr(2)), , ''
nil,  sw_hide);
Or with '' instead of nil

ShellExecute(I, 'open', PChar('s:\public\homch2.bat '+ ParamStr(1) + ParamStr(2)), , '' , '', sw_hide);
Avatar of Dark_King

ASKER

[Error] chechd.dpr(35): Expression expected but ',' found

Some thing is wrong here in your examples Epsylon
And a thing it while give me incompatible types 'Integer' and 'PChar'
Avatar of kretzschmar
hi eps :-)
try this

ShellExecute(I, 'open', PChar('s:\public\homch2.bat '+ ParamStr(1) + ' ' + ParamStr(2)), '' , '', sw_hide);
I found this, how do I use the lpParameters in my example.


HINSTANCE ShellExecute(

    HWND hwnd,     // handle to parent window
    LPCTSTR lpOperation,     // pointer to string that specifies operation to perform
    LPCTSTR lpFile,     // pointer to filename or folder name string
    LPCTSTR lpParameters,     // pointer to string that specifies executable-file parameters
    LPCTSTR lpDirectory,     // pointer to string that specifies default directory
    INT nShowCmd      // whether file is shown when opened
   );

lpFile

Pointer to a null-terminated string that specifies the file to open or print or the folder to open or explore. The function can open an executable file or a document file. The function can print a document file.

lpParameters

If lpFile specifies an executable file, lpParameters is a pointer to a null-terminated string that specifies parameters to be passed to the application.
If lpFile specifies a document file, lpParameters should be NULL.
Hi meikl   (o:

Dark King, also make sure that you use double quotes ("), when command and/or parameters contain spaces.

ShellExecute(I, 'open', PChar('"s:\public\homch2.bat" "'+ ParamStr(1)+'" "'+ParamStr(2))+'"', '' , '', sw_hide);

In most cases I leave lpParameters and lpDirectory empty (='').
ASKER CERTIFIED SOLUTION
Avatar of alanwhincup
alanwhincup

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If that doesnt work then try:

ShellExecute(I, 'Open', PChar('s:\public\homch2.bat'), PChar(ParamStr(1) + ParamStr(2)), '', SW_HIDE);
I try all of your examples and it was close "EPS"  but one work right a way and earn the point.