Solved

ShellExecute

Posted on 2001-09-10
11
879 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month6 days, 11 hours left to enroll

636 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