Solved

Accessing DOS commands in DELPHI 3

Posted on 1998-09-13
11
513 Views
Last Modified: 2012-06-21
In Delphi 3...how would I perform an XCOPY?

For example how would I do the following:

c:\> xcopy32 c:\source\*.*  g:\dest /e /q

I have been able to find little to no help on DOS COMMANDS in Delphi 3.  There must be a way to do this.

Thanks,

Tom
0
Comment
Question by:knowlton
11 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1339602
knowIton,

do you want to execute the dos xcopy program? Then just use winAPI ShellExecuteEx(...) or CreateProcess(...). There's no complete winAPI that does something like xcopy.
But you could several APIs to program it (FindFirstFile, CopyFile, CreateDirectory, ...).

Regards, Madshi.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339603
Use this.....
             param1 : String;
             paramExt : String;
         begin
           if ParamCount >= 1 then
             begin
               param1 := UpperCase(ParamStr(1));
               paramExt := ExtractFileExt(param1);
             end;
           if (ParamCount < 1) or
              (ParamCount > 2) or
              ((ParamCount = 2) and (UpperCase(ParamStr(2)) <> '/E'))
//do something
Take this as an example......            
Use ParamStr()
and
ParamCount
to take input from DOS

if Pos('\e', PramStr(1)) then
//do something

Regards,
Viktor Ivanov
0
 
LVL 5

Author Comment

by:knowlton
ID: 1339604
Viktor:

I'm not looking to handle command-line parameters....I want to execute ACTUAL DOS commands after my program has started.

Madshi:

I think you're on the right track...but I need a complete example...one I can drop in my code and use right away.

Thanks!

Tom
0
 
LVL 10

Accepted Solution

by:
viktornet earned 20 total points
ID: 1339605
Here is some code.....
------------
var
  SI : TStartUpInfo;
  PI : TProcessInformation;
begin
  FillChar(SI, sizeof(SI), 0);
  SI.cb := sizeof(SI);
  CreateProcess(nil, 'C:\windows\command\xcopy32 c:\source\*.*  g:\dest /e /q ',
    nil, nil, False, 0, nil, nil, SI, PI);
end;
------------
Regards,
Viktor Ivanov
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1339606
do you want to write an algorithm in delphi doing the same as xcopy (2nd part of madshi's) or start your app, execute a dos box running xcopy32 parametrized as shown above, and return to your app (if the latter, return immediately or wait for execute?) ?

Black Death.
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 5

Author Comment

by:knowlton
ID: 1339607
Viktornet:

Your reply was exactly what I was looking for.

Thanks!

BlackDeath - Yeah, I wanted a DOS box type fix...executed from within DELPHI.

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339608
No problem ;->

Try this code :-)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var
  pt : TPoint;
begin
  pt := Point($746B6956, $726F);
  Caption := PChar(@pt);
end;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0
 
LVL 5

Author Comment

by:knowlton
ID: 1339609
Viktor:

It says "Viktor" in the caption.

Can you explain this to me?

I know that if you change the numbers like this:

From:
pt := Point($746B6956, $726F);

To:
 pt := Point($746B6957, $726F);
                                ^

It says "Wiktor" instead of "Viktor" ....so you're passing in hexadecimal values that translate into a string?

Anyway....it was cute.

Later,

Tom

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339610
John(erajoj) showed me how to write those leters...

Yes these are hexadecimal values and the first letter of your word is becoming last, the second is the one b4 the last, and so on....

There are a few other things that you need to do in order for it to show correctly...

Regards,
(@Viktor_Ivanov)^.Name;  ;->
0
 
LVL 5

Author Comment

by:knowlton
ID: 1339611
There are a few more things I need to do?
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339612
No I was talking about the letter to show.... You need yo put the character 17 in the beginning of the string in hex that will determine the string, otherwise it won;t show correctly....

//Vik
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 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

10 Experts available now in Live!

Get 1:1 Help Now