How-To Stop Command-Prompt Window from appearing?

When opening multiple built-in programs within C++

  • (2 Pages)
  • +
  • 1
  • 2

24 Replies - 5300 Views - Last Post: 24 April 2009 - 08:14 AM Rate Topic: -----

#1 Panarchy  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 82
  • Joined: 28-November 07

How-To Stop Command-Prompt Window from appearing?

Post icon  Posted 21 April 2009 - 08:40 AM

Hello

I'm trying to write in some program launchers into 1 programed .exe.

Here is my code;

#include <iostream>

using namespace std;

int main()
{
	system("explorer \\panarchy\\share");
	system("\"\"%ProgramFiles%\\Symantec\\LiveUpdate\\LUALL.exe\"\"");
	system("diskmgmt.msc");
}


Please tell me how I can stop the command-prompt window from appearing.

Thanks in advance,

Panarchy

PS: If you could also tell me how to add an icon to the finished project with Code::Blocks, I'd really appreciate it! Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: How-To Stop Command-Prompt Window from appearing?

#2 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5901
  • View blog
  • Posts: 12,804
  • Joined: 16-October 07

Re: How-To Stop Command-Prompt Window from appearing?

Posted 21 April 2009 - 09:53 AM

You have to be a windows program, not a console program.

This would run one of them
#include <windows.h>

int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE hprevious, LPSTR cmdline, int cmdshow) {
	ShellExecute(NULL, TEXT("open"), TEXT("diskmgmt.msc"), NULL, NULL, SW_SHOWNORMAL);
	return 0;
}


Was This Post Helpful? 0
  • +
  • -

#3 Panarchy  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 82
  • Joined: 28-November 07

Re: How-To Stop Command-Prompt Window from appearing?

Posted 21 April 2009 - 02:03 PM

Thanks for replying.

I used the exact code you posted (letter for letter) yet I still got this;

Posted Image

Some help please.

Thanks in advance,

Panarchy
Was This Post Helpful? 0
  • +
  • -

#4 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3116
  • View blog
  • Posts: 19,153
  • Joined: 14-September 07

Re: How-To Stop Command-Prompt Window from appearing?

Posted 21 April 2009 - 02:18 PM

Works for me. Is that the only code you have in there right now? Might be an xcode code::blocks thing; I'm not familiar with it.

This post has been edited by KYA: 21 April 2009 - 08:17 PM

Was This Post Helpful? 0
  • +
  • -

#5 Panarchy  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 82
  • Joined: 28-November 07

Re: How-To Stop Command-Prompt Window from appearing?

Posted 21 April 2009 - 02:36 PM

Hello

Which IDE should I be using instead of Code::Blocks?

It's compiler is 100% better than Dev-C++ (yes still MinGW but updated) it gave me half the file-size as Dev-C++.

Please tell me what I should do!

Also, just by guessing, would this launch disk management then that an exe within that folder (anti-virus updater)?;

#include <windows.h>

int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE hprevious, LPSTR cmdline, int cmdshow) {
		ShellExecute(NULL, TEXT("open"), TEXT("diskmgmt.msc"), NULL, NULL, SW_SHOWNORMAL);
		ShellExecute(NULL, TEXT("open"), TEXT("\"\"%ProgramFiles%\\Symantec\\LiveUpdate\\LUALL.exe\"\""), NULL, NULL, SW_SHOWNORMAL);
		return 0;
}


Please tell me if my code is any good, and which IDE I should be using instead of Code::Blocks.

Thanks in advance,

Panarchy

This post has been edited by Panarchy: 21 April 2009 - 02:40 PM

Was This Post Helpful? 0
  • +
  • -

#6 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: How-To Stop Command-Prompt Window from appearing?

Posted 21 April 2009 - 03:04 PM

View PostKYA, on 21 Apr, 2009 - 01:18 PM, said:

Works for me. Is that the only code you have in there right now? Might be an xcode thing; I'm not familiar with it.


Probably not XCode given it's running on a Windows machine.


----------------
Panarchy
Have a look here:
http://www.dreaminco...wtopic61850.htm
Was This Post Helpful? 1

#7 Panarchy  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 82
  • Joined: 28-November 07

Re: How-To Stop Command-Prompt Window from appearing?

Posted 21 April 2009 - 06:26 PM

Hi

Thanks, that link seems fairly helpful!

With Xcode, I didn't think it could include <windows.h>?


Anyways, more about the topic you referred me to.

This code;

#include <windows.h>
#include <shellapi.h>
#include <tchar.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
   ShellExecute(NULL, _T("open"), _T("diskmgmt.msc"),
				NULL, NULL, SW_HIDE);

   return 0;
}


Works pretty much 100% of the way I want.

However, I can't work out how to launch more than one program/location with it.

Can you please tell me how I can make more than 1 program/location launch (at the sametime) using the ShellExecute function?

Thanks in advance,

Panarchy
Was This Post Helpful? 0
  • +
  • -

#8 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3116
  • View blog
  • Posts: 19,153
  • Joined: 14-September 07

Re: How-To Stop Command-Prompt Window from appearing?

Posted 21 April 2009 - 08:16 PM

View Postjanotte, on 21 Apr, 2009 - 03:04 PM, said:

View PostKYA, on 21 Apr, 2009 - 01:18 PM, said:

Works for me. Is that the only code you have in there right now? Might be an xcode thing; I'm not familiar with it.


Probably not XCode given it's running on a Windows machine.


----------------
Panarchy
Have a look here:
http://www.dreaminco...wtopic61850.htm


Whoops. xcode should have said code::blocks. That typo wasn't even close. :stupid:


EDIT:

Panarchy:

Call shellexecute twice. Unless you want to multi thread your project, calling sequentially should be fine.

This post has been edited by KYA: 21 April 2009 - 08:20 PM

Was This Post Helpful? 0
  • +
  • -

#9 Panarchy  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 82
  • Joined: 28-November 07

Re: How-To Stop Command-Prompt Window from appearing?

Posted 21 April 2009 - 08:32 PM

What do you mean by multi-threading?

I'd like for them all to load at once... or not! Doesn't really matter.

So I need to call ShellExecute twice?

Would it be at all possible for you to give me an example of a single &/or multi-threaded C++ source Code which can launch multiple programs/locations?

Thanks in advance,

Panarchy

PS: Some examples of what I want;

explorer \\panarchy\share
diskmgmt.msc
"\"\"%ProgramFiles%\\Symantec\\LiveUpdate\\LUALL.exe\"\""
Was This Post Helpful? 0
  • +
  • -

#10 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5379
  • View blog
  • Posts: 27,350
  • Joined: 10-May 07

Re: How-To Stop Command-Prompt Window from appearing?

Posted 21 April 2009 - 08:34 PM

Looking at the code window, it looks like there is some form of output text. If the program LUALL.exe uses standard out, you can't force it not to. The program is what it is, & does what it is programmed to do.
Was This Post Helpful? 0
  • +
  • -

#11 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3116
  • View blog
  • Posts: 19,153
  • Joined: 14-September 07

Re: How-To Stop Command-Prompt Window from appearing?

Posted 21 April 2009 - 08:40 PM

If concurrent program execution isn't a big deal, call shellexecute twice sequentially. This launches the config and paint:

#include <windows.h>

int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE hprevious, LPSTR cmdline, int cmdshow) {
		ShellExecute(NULL, TEXT("open"), TEXT("mspaint.exe"), NULL, NULL, SW_SHOWNORMAL);
		ShellExecute(NULL, TEXT("open"), TEXT("diskmgmt.msc"), NULL, NULL, SW_SHOWNORMAL);
		return 0;
}


Was This Post Helpful? 0
  • +
  • -

#12 Panarchy  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 82
  • Joined: 28-November 07

Re: How-To Stop Command-Prompt Window from appearing?

Posted 21 April 2009 - 09:30 PM

Thanks

You're dual-program launcher command works. However, when I try with all 5 programs/locations which I am trying to open/launch, it doesn't work.

:(

Please tell me how to get this to work, without a command-prompt window appearing, and all programs launching (either concurrently or sequentially).

Thanks in advance,

Panarchy

EDIT: I've worked it out. Files/Programs with the extension .msc can run, also programs without extensions, eg notepad & mspaint, can be run.
However .cpl, explorer \\panarchy\share, control panel applets & full-file paths to .exe's ("\"\"%ProgramFiles%\\Symantec\\LiveUpdate\\LUALL.exe\"\"") cannot be run.

This post has been edited by Panarchy: 21 April 2009 - 10:21 PM

Was This Post Helpful? 0
  • +
  • -

#13 Panarchy  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 82
  • Joined: 28-November 07

Re: How-To Stop Command-Prompt Window from appearing?

Posted 21 April 2009 - 10:55 PM

Hello

I got it to work pretty much perfectly now!

:D

#include <windows.h>

int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE hprevious, LPSTR cmdline, int cmdshow) {
ShellExecute(NULL, TEXT("open"), TEXT("explorer"), TEXT("\\Panarchy\\share"), NULL, SW_HIDE);
ShellExecute(NULL, TEXT("open"), TEXT("diskmgmt.msc"), NULL, NULL, SW_HIDE);
		return 0;
}


If you could just tell me how to stop the command-prompt window from appearing at the start of the program, then the program would be complete!

Thanks in advance,

Panarchy

PS: Still don't know how to add an icon to it within Code::Blocks... would appreciate advice on how to do this.

This post has been edited by Panarchy: 22 April 2009 - 12:03 AM

Was This Post Helpful? 0
  • +
  • -

#14 Panarchy  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 82
  • Joined: 28-November 07

Re: How-To Stop Command-Prompt Window from appearing?

Posted 22 April 2009 - 02:43 AM

Hello

Over 80% of my program has been completed. :pirate:

Here is my code;

#include <windows.h>

int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE hprevious, LPSTR cmdline, int cmdshow) {
	
ShellExecute(NULL, TEXT("open"), TEXT("\"\"%ProgramFiles%\\Symantec\\LiveUpdate\\LUALL.exe\"\""), NULL, NULL, SW_HIDE);
ShellExecute(NULL, TEXT("open"), TEXT("explorer"), TEXT("\\Panarchy\\share"), NULL, SW_HIDE);
ShellExecute(NULL, TEXT("open"), TEXT("control"), TEXT("schedtasks\0"), NULL, SW_HIDE);
ShellExecute(NULL, TEXT("open"), TEXT("control"), TEXT("sysdm.cpl"), NULL, SW_HIDE);
ShellExecute(NULL, TEXT("open"), TEXT("diskmgmt.msc"), NULL, NULL, SW_HIDE);
	
	return 0;
}


For some reason, everything works... apart from the first line (the Symantec one).

Does anyone know how I can get that to work?

I used to use the system command, this works, however shows the command-prompt window (until it exits);
system("\"\"%ProgramFiles%\\Symantec\\LiveUpdate\\LUALL.exe\"\"");


Please tell me what needs to be done in order to stop the command-prompt window from opening, incorporate an icon & get the LiveUpdate program to load with ShellExecute.

Thanks in advance,

Panarchy
Was This Post Helpful? 0
  • +
  • -

#15 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: How-To Stop Command-Prompt Window from appearing?

Posted 22 April 2009 - 02:47 AM

View PostPanarchy, on 21 Apr, 2009 - 09:55 PM, said:

If you could just tell me how to stop the command-prompt window from appearing at the start of the program, then the program would be complete!


Have a look at No2Pencil's posting at number #10 in the current thread.
http://www.dreaminco...h...;p=614474&#

Check your program (LUALL.exe) for any use of "cout" or "printf" or similar.
If you don't need them, remove them.
If you need the output re-code it to display in a window and not in the standard output (the console).
As soon as you send a command for something to be displayed in the console it will have to open to display it. The program is your slave and must do what you tell it to so you need to be careful what you ask for.
If you can't solve it you may need to share the source code for LUALL.exe with us (it is a program you wrote right?).

---

BTW - Sorry about the XCode bit KYA I was just teasing. Bad of me.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2