Jump to content
NBilov

How to execute a cmd file in delphi in invisible mode

Recommended Posts

When I run a cmd file in delphi by shellexecute method it raises black cmd window during execution. How can I execute it in ordinary vcl windows application invisibly without this window.

 

Share this post


Link to post

What does "run a cmd file" mean? 

 

My guess is that you need to use CreateProcess with the CREATE_NO_WINDOW flag. 

Share this post


Link to post
35 minutes ago, NBilov said:

When I run a cmd file in delphi by shellexecute method it raises black cmd window during execution. How can I execute it in ordinary vcl windows application invisibly without this window.

 

Try to pass SW_HIDE as the last parameter.

Share this post


Link to post
1 hour ago, PeterBelow said:

Try to pass SW_HIDE as the last parameter.

This relies on the other process to respond to that flag, and they often won't. And certainly they won't of they are console apps. It's a very common mistake to try to run a console app with ShellExecuteEx which is designed to execute shell verbs not to create processes. 

Share this post


Link to post

In this cmd files I almost never use any console programs. Only program with datamodule , which executes a task and closes. Or batch scripts - mostly file operations and git commands

Share this post


Link to post

If you need to capture and process the output of the cmd, I would even advise to use CreateProcess with STARTF_USESTDHANDLES. I have an example here, but it's a bit of a confusing sample because the reading of the pipes happens in the DoCommand procedure, I should take some time to write a cleaner example...

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×