Solved

DELPHI-MSDOS

Posted on 2001-06-11
9
407 Views
Last Modified: 2010-04-06
HOW CAN I CALL A MSDOS PROGRAM FROM DELPHI, FOR EXAMPLE I WANT TO EXECUTE TRACERT FROM DELPHI,
HOW CAN I DO IT?????
0
Comment
Question by:Iamme
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 9

Expert Comment

by:ITugay
ID: 6177341
Hi Iamme,
somesthing like this
ShellExecute(handle,'open','command','/c c:\tr\tracert.exe ',nil,SW_SHOW);
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6177344
Hi Iamme,
do not forget include ShellApi unit in uses clause.
0
 

Author Comment

by:Iamme
ID: 6177354
tnks.......I'll try it................wait me, and I have you an answer..if you have more examples please send it to me
0
 
LVL 22

Expert Comment

by:mnasman
ID: 6177377
Hello

 try this
WinExec('command.com /c tracert 172.16.3.39',sw_ShowNormal);
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Accepted Solution

by:
djadja earned 100 total points
ID: 6180702
Naughty, naughty - hard coding the command processor! It's really not needed...
Also WinExec is a backwards compatibility function that shouldn't be used according to the help...

However, the following cut down should work fine:

uses ShellAPI;

ShellExecute(Application.Handle,PChar('open'),PChar('c:\tr\tracert.exe'),nil,nil,SW_SHOWNORMAL);
0
 
LVL 17

Expert Comment

by:geobul
ID: 6180893
djadja: the same applies to your answer. PChar is not necessary here because Delphi does it for you. Also, when the app is an exe file, specifying 'open', 'print' or nothing does the same - executes the app.

Here is more complex but flexible way which allows you to wait for the completion of the new app.

function ExecApplication(APPName, CmdLine: String; ShowMode: DWord; WaitToExit: Boolean): DWord;
//executes as well WIN and DOS application
var StartInfo: TStartupInfo;
  ProcInfo: TProcessInformation;
begin
  StartInfo.cb:=SizeOf(StartInfo);
  FillChar(StartInfo, SizeOf(StartInfo), 0);
  StartInfo.dwFlags:=STARTF_USESHOWWINDOW;
  StartInfo.wShowWindow:=ShowMode;
  if AppName<>'' then CreateProcess(PChar(APPName), PChar(CmdLine), nil, nil, False, 0, nil, nil, StartInfo, ProcInfo)
  else CreateProcess(nil, PChar(CmdLine), nil, nil, False, 0, nil, nil, StartInfo, ProcInfo);
  if WaitToExit then WaitForSingleObject(ProcInfo.hProcess, INFINITE);
  GetExitCodeProcess(ProcInfo.hProcess, Result);
  CloseHandle(ProcInfo.hProcess);
  CloseHandle(ProcInfo.hThread );
end;

Usage:
ExecApplication('','c:\tr\tracert.exe',SW_SHOWNORMAL,false);

Regards, Geo
0
 
LVL 17

Expert Comment

by:geobul
ID: 6180946
I would like to mention that it is always better to post comments only because:
- proposing an answer locks the question and removes it from the queue;
- the question becomes out of sight for other experts and the questioner cannot receive different ideas from other people - he has that right, doesn't he?;
- every one problem always has more than one possible solution - let the questioner to decide which one best fits his needs.

Regards, Geo
0
 

Expert Comment

by:djadja
ID: 6181282
>> the same applies to your answer
What do you mean? - I haven't used WinExec or command.com?

Sorry about posting as an answer - I've been picked up on that on another post!

Yep - Delphi will convert constant strings to it's PChar equivalent. It's just I ALWAYS use PChar around the string parameters to show its a DLL function as opposed to a pascal 'local' function.

PS. I think it's missing a WaitForInputIdle...

Taken from Delphi Win32 help..."The calling thread can use the WaitForInputIdle function to wait until the new process has finished its initialization and is waiting for user input with no input pending. This can be useful for synchronization between parent and child processes, because CreateProcess returns without waiting for the new process to finish its initialization. For example, the creating process would use WaitForInputIdle before trying to find a window associated with the new process."
0
 
LVL 17

Expert Comment

by:geobul
ID: 6181530
I mean that every one piece of code can be rewritten another way and it's not a reason to post an answer. As far as you didn't want to, I'm sorry too, forget it.

About your PS: CreateProcess returns the handle of the newly created process which is enough for waiting for its end. I'm not going to find its window handle or to communicate with it. The calling app becomes frozen and inaccesible until the called process is working. This is when the last parameter is 'true' only.

Regards, Geo
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Convert Jpg /PNG To GIF 5 103
Run video youtube webbrowse 10 45
Find and Replace Stream with 0s 8 50
Delphi...Split view - idea? 1 0
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 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

9 Experts available now in Live!

Get 1:1 Help Now