?
Solved

Executing Dos commands

Posted on 1999-12-05
10
Medium Priority
?
279 Views
Last Modified: 2010-04-06
I want to execute the following line without showing the prompt window in no way.
ShellExecute( Self.Handle, 'open', PChar( 'C:\WINDOWS\COMMAND\COMMAND.COM' ),
                              PChar( '/C DIR > ANYFILE.TXT'),
                              PChar( 'C:\WINDOWS\COMMAND'),
                              SW_SHOWMINIMIZED );
How could I do this?

P.S. I've used all combinations of SW_HIDE or SW_* and none of them give the result i'm looking for.
0
Comment
Question by:rarigo
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2256275
hi rarigo,

try this

WinExec('C:\WINDOWS\COMMAND\COMMAND.COM /C DIR > ANYFILE.TXT', SW_HIDE);

hoping there is no typo

meikl
0
 

Author Comment

by:rarigo
ID: 2256295
Hi kretzschmar,

    It doesn't matter WinExec, ShellExecute. It's the same. They show you the MS-DOS Prompt Window. The better way so far would be use any of them with the SW_MINIMIZED.


Tchau,
Reginaldo
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2256343
hi rarigo,

not by me,
have you tried it ?

meikl ;-)
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 17

Accepted Solution

by:
inthe earned 210 total points
ID: 2256534
when i use the sw_hide const in winexec etc it is hidden ok so dunno why not for you but what about trying createprocess instead:


var
  tsi: TStartupInfo;
  tpi: TProcessInformation;
  code : DWORD;
  comspec : array[0..511] of char;
  cmd : string;
 
begin
  FillChar(comspec, sizeof(comspec), 0);
  GetEnvironmentVariable('comspec', comspec, sizeof(comspec));
  // comspec gets the path to the command shell, command.com or cmd.exe   // I use this to execute a dos command. It is not required to execute a windows app
  cmd := comspec+' /c dir > anyfile.txt';
 
  FillChar(tsi, SizeOf(TStartupInfo), 0);
  tsi.cb := SizeOf(TStartupInfo);
  tsi.wShowWindow := SW_HIDE;
  tsi.dwFlags := STARTF_USESHOWWINDOW;
 
  if CreateProcess(nil, PChar(cmd), nil, nil, True, 0, nil, nil, tsi,tpi) then
  begin
    WaitForSingleOject(tpi.hProcess, INFINITE);
    GetExitCodeProcess(tpi.hProcess, code);  // exit code value
  end;
end;
0
 

Author Comment

by:rarigo
ID: 2257078
Hi kretzschmar and inthe,

   Yes, I've tried WinExec and Createprocess with SW_HIDE flag before posting my question to this forum and
does not work. I still see the DOS-Prompt window poping up on my screen.
As I've told before the better way till now proved to be use SW_SHOWMINIMIZE because all you'll see is a dosprompt window minimized on taskbar while command is running.
For a fast command like DIR it's not that bad. But what if I execute a dir /s command?


Tchau,
Reginaldo
0
 
LVL 1

Expert Comment

by:she3i3i
ID: 2258477
Listening...
0
 

Author Comment

by:rarigo
ID: 2267195
   Well. Let me close this question because it's bothering me this open question and i'll accept inthe comments as an answer because he tried it a little harder even though as I've told I had experimented all these before posting the question to this forum.



Tchau,
Reginaldo
0
 

Author Comment

by:rarigo
ID: 2267205
  I've already made a comment to this. I'm giving a B to keep your average.
0
 
LVL 17

Expert Comment

by:inthe
ID: 2267870
?
thanks for the points but id prefer if we had found the answer..
is it still not working?
0
 

Author Comment

by:rarigo
ID: 2270495
Hi Inthe,

   Not yet. I kinda of gave it up for a while maybe sometime in the future i'll think of that.

    See ya.

Tchau,
Reginaldo
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
The video will let you know the exact process to import OST/PST files to the cloud based Office 365 mailboxes. Using Kernel Import PST to Office 365 tool, one can quickly import numerous OST/PST files to Office 365. Besides this, the tool also comes…

593 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