Solved

ShellExecute

Posted on 2001-09-10
11
873 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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
 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

772 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