Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Dos commands from delphi?????

Posted on 1999-10-20
12
Medium Priority
?
1,019 Views
Last Modified: 2008-03-10
I am writing a delphi program that needs to execute
dos commands such as: MAP xx:=........
How do I execute those type of commands and checking
to see if the command was successfully excuted?
I tried using WinExec but it would execute it open
a dos window and close it immediately, i don't know
if the dos command executed successfully or not.
I put the dos command into a .bat file and execute
the .bat file.  However, I don't know if it executed
right or not. HELP!!!!

I also tried using the ShellExecute, same results, not sure
if i'm doing it right or not.

thanks
0
Comment
Question by:waipahu
[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
  • 3
  • 2
  • 2
  • +5
12 Comments
 
LVL 6

Expert Comment

by:edey
ID: 2142914
Do you need to be able to execute all available dos commands, or just a few specific ones?  What exactly do you need to use these commands for, there may be a better solution.

GL
Mike
0
 

Author Comment

by:waipahu
ID: 2142951
Right now I need to execute a MAP command.
Copy command
0
 
LVL 3

Expert Comment

by:philipleighs
ID: 2142983
You can use ShellExecute like this:

ShellExecute(Application.Handle, 'open', 'COMMAND.COM /C', ' MAP xxx', nil, ...

I don't know about the return value of MAP though.

Cheers,
Phil.
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 27

Expert Comment

by:kretzschmar
ID: 2143050
hi waipahu,

sounds like netware mapping.
in a dos shell will this not work,
i guess, after close the shell,
the mapping is gone.

you must do the mapping(s) over the win-api

meikl
0
 
LVL 7

Expert Comment

by:RBertora
ID: 2143412
Doging the original question...
because it has been answered by Phil...

This might be helpfull :(dunno netware?)

To map to different PC harddrives use:

WNetAddConnection("\\Server\Path\", "pwd", "K:");

or WNetAdconnection2 :

procedure TForm1.Button1Click(Sender: TObject);
var
  Net : TNETRESOURCE;
begin

  with Net do
  begin
      dwScope := RESOURCE_CONNECTED ;
      dwType := RESOURCETYPE_DISK;
      dwDisplayType := RESOURCEDISPLAYTYPE_SHARE;
      dwUsage := RESOURCEUSAGE_CONNECTABLE;
      lpLocalName := 'K:';
      lpRemoteName := PChar('\\ntdata\foldername');
      lpComment := Pchar('None');
      lpProvider := Nil;
  end;

 WNetAddConnection2(Net,'Password','RBertora',CONNECT_UPDATE_PROFILE );

end;



to move files use:

MoveFile(Pchar('OldfileName'),Pchar('NewFileName'));

where the filenames include the full path ie
//mapdrive/directory/filename.ext

to copy files use similar function copyfile.


Rob ;-)
0
 
LVL 3

Expert Comment

by:philipleighs
ID: 2143433
>>because it has been answered by Phil...

But you or meikl are providing the real help.  ;-)

Cheers,
Phil.
0
 

Author Comment

by:waipahu
ID: 2143517
Great!!! The WNetAddConnect worked great!!! Thanks
HOw do I disconnect the connection?

Hey, where do you get all these "WNet" commands?????? also
where can I find window commands for delphi???? There is so much
operating system commands that I want to do, but I don't know where
to get those type of information.

THANKS SO MUCH!!!!
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2143549
I think it was WNetCancelConnection or something like this. If you want to know more, open the win32.hlp file (contained in your delphi\bin or delphi\help or delphi\mshelp directory). There you see the most important windows APIs. Most of them are already contained in Windows.pas so you can simply call them.

Regards, Madshi.
0
 

Author Comment

by:waipahu
ID: 2143594
Great!!! The WNetAddConnect worked great!!! Thanks
HOw do I disconnect the connection?

Hey, where do you get all these "WNet" commands?????? also
where can I find window commands for delphi???? There is so much
operating system commands that I want to do, but I don't know where
to get those type of information.

THANKS SO MUCH!!!!
0
 
LVL 17

Expert Comment

by:inthe
ID: 2143657
yep it is WNetCancelConnection2(pchar(SomeMappedDrive),0,True);
 to disconnect a mapped drive and for finding these WinAPI functions id advise getting the "tomes of delphi" series of books from amazon etc and also read the help file in :
delphi/borland shared/MShelp/win32.hlp  (24mgs in size)
it will keep you busy for quite some time ;-)
Regards Barry
0
 
LVL 7

Accepted Solution

by:
RBertora earned 800 total points
ID: 2144628
Hi waipahu,
as Madshi said:

the win32.hlp file (contained in your delphi\bin or delphi\help or delphi\mshelp directory) is where you find this stuff... thought the examples are all in C you can do it all with delphi too.

I post as answer since my previous comment seemed
to help you.
Rob ;-)
 
0
 

Expert Comment

by:jimburns
ID: 2157396
Well, addressing the original question :)  I'll leave you with this (I am the Author):
-----------
Many folks have asked on this list how to shut down a command line app
programmatically just like the Close on Exit checkbox in the property sheet
for a command-line/DOS app.  I don't know how many folks are aware of this technique, but
I've never noticed any significant answers to the question on this list.
Most of the time the issue centers around programmatically building a
shortcut to the dos app.  And while there have been many examples on how to
build a shortcut, I've not seen anyone specifically show how to
programmatically check that Close on Exit box.

Well for those of you needing a quick fix try this:

The Win95 command-line interpreter is called command.com and while it
accepts command-line arguments and even command-line switches there is no specific mention of them within the Win95 help.

The WinNT command-line interpreter is called cmd.exe and it also accepts
command-line arguments and switches, but it is fully detailed in the WinNT
help system.

Here is an excerpt:

---------------------------------

Starts a new instance of the Windows/NT command interpreter

CMD [/X | /Y] [/A | /U] [/Q] [[/C | /K] string]

/C      Carries out the command specified by string and then terminates
/K      Carries out the command specified by string but remains
/Q      Turns the echo off
/A      Causes the output of internal commands to a pipe or file to be ANSI
/U      Causes the output of internal commands to a pipe or file to be Unicode
/T:fg   Sets the foreground/background colors (see COLOR /? for more info)
/X      Enable extensions to the Windows NT version of CMD.EXE
/Y      Disable extensions to the Windows NT version of CMD.EXE

Note that multiple commands separated by the command separator '&&'
are accepted for string if surrounded by quotes

---------------------------------

Well, it just so happens that at the very least, the /c switch is also
valid under command.com under Win95.  Woo Hoo.  As I'm sure you can tell
already, the answer lies in running the command interpreter and sending it
command-line parameters, not in trying to run the DOS app and letting Win95
start the command interpreter and set it's own command-line parameters.
When you mix this with the use of the /c switch, voila'!

Thus, say you want to use pkunzip to get a listing of the contents and
automatically shut-down the command would be:

ExecuteAndWait('command.com /c pkunzip -v c:\path\zipfile.zip > zipview.txt')

-----------

You would then need something like this.  Note: Line Length = 150 chars

{-----------------------------------------------------------------------------------------------------------------------------------------------------
Name:         ExecuteAndWait
Description:  Executes an external executable and waits for its completion before continuing, returning the exit code of the process

}
function ExecuteAndWait(const CommandLine : string) : _DWORD;
var
  tSI : TStartupInfo;
  tPI : TProcessInformation;
  dw  : _DWORD;
begin
  Result := 0;
  FillChar(tSI, sizeof(TStartupInfo), 0);
  tSI.cb := sizeof(TStartupInfo);
  if CreateProcess(nil, pchar(CommandLine), nil, nil, False, 0, nil, nil, tSI, tPI) then begin
    if WaitForSingleObject(tPI.hProcess, INFINITE) = WAIT_OBJECT_0 then begin
      if GetExitCodeProcess(tPI.hProcess, dw) then begin

        Result := dw;
        //if dw = 0 then begin                                                                       // sExe returned errorlevel 0, usually means Ok
        //  Result := True;
        //end
        //else begin                                                                                 // sExe returned something else, value in dw
        //
        //end;
      end;
    end;
    CloseHandle(tPI.hProcess);
    CloseHandle(tPI.hThread);
  end
  else begin
    // MessageBox 'CreateProcess Failed'
    // Result := False;
  end;
end;
------------------------

HTH with regard to anwering the ORIGINAL question!  :)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

660 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