Solved

ShellExecute

Posted on 2001-09-10
11
868 Views
Last Modified: 2010-04-06
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 ????
0
Comment
Question by:Dark_King
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 6470681
Try

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

Expert Comment

by:Epsylon
ID: 6470687
Or with '' instead of nil

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

Author Comment

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

Some thing is wrong here in your examples Epsylon
0
 
LVL 6

Author Comment

by:Dark_King
ID: 6470755
And a thing it while give me incompatible types 'Integer' and 'PChar'
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6470768
hi eps :-)
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 6470793
try this

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

Author Comment

by:Dark_King
ID: 6470861
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.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6471147
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 (='').
0
 
LVL 5

Accepted Solution

by:
alanwhincup earned 200 total points
ID: 6471588
Try this:

ShellExecute(I, 'Open', PChar('s:\public\homch2.bat'), PChar(ParamStr(1) + ' ' + ParamStr(2)), '', SW_HIDE);

I havent tested it but it should work.
0
 
LVL 5

Expert Comment

by:alanwhincup
ID: 6471599
If that doesnt work then try:

ShellExecute(I, 'Open', PChar('s:\public\homch2.bat'), PChar(ParamStr(1) + ParamStr(2)), '', SW_HIDE);
0
 
LVL 6

Author Comment

by:Dark_King
ID: 6473350
I try all of your examples and it was close "EPS"  but one work right a way and earn the point.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now