2vision2
2vision2

Reputation: 5023

call default windows executables in C program

I used system() function to call certmgr.exe in my C code. Once I start my executable, a command promt appears showing certificate successfully installed.

But I dont want the command promt to be opened. How to do that??

any other ways available to call the "exe's" in C language..

thanks,,,

Upvotes: 5

Views: 836

Answers (5)

2vision2
2vision2

Reputation: 5023

Answered by T.E.D in this link helped me finally...

This may help some one in future...

Others have mentioned using CreateProcess (presumably to redirect the output). The general reason this happens is that the program you are running via "system" is a command-line program. If it is something you compile yourself, you can get rid of the console window by building it as a GUI program instead. You should be able to do this by including Windows.h and using WinMain() as your entry point instead of main()

Upvotes: 0

David Heffernan
David Heffernan

Reputation: 613302

The easiest way to do this on Windows is to call ShellExecute. Pass SW_HIDE to make sure that no console window is shown.

You could alternatively use CreateProcess but it's a little trickier to call. Use the CREATE_NO_WINDOW flag to suppress the console window.

Upvotes: 5

Zaid Amir
Zaid Amir

Reputation: 4785

I wouldn't use system to run anything.. this is why: http://www.cplusplus.com/forum/articles/11153/

You can use ShellExecute to run applications http://msdn.microsoft.com/en-us/library/bb762153(VS.85).aspx Pass SW_HIDE and you're done.

Upvotes: 4

hmjd
hmjd

Reputation: 122001

WINAPI has a CreateProcess() function that you could use to run another executable. There are several arguments to this function which may provide a mechanism for not displaying the console window of certmgr.exe (from process creation flags argument):

CREATE_NO_WINDOW The process is a console application that is being run without a console window. Therefore, the console handle for the application is not set.

Upvotes: 2

dirkgently
dirkgently

Reputation: 111210

There is no way to run cmd.exe silently/in background. However, do look up the start command and its associated /B option:

Starts a separate window to run a specified program or command.

START ["title"] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED] [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL] [/AFFINITY ] [/WAIT] [/B] [command/program] [parameters]

[...] B Start application without creating a new window. The application has ^C handling ignored. Unless the application enables ^C processing, ^Break is the only way to interrupt the application.

You'll be better off with CreateProcess.

Upvotes: 3

Related Questions