Click to See Complete Forum and Search --> : How-To Stop Command-Prompt Window from appearing?


Panarchy
April 21st, 2009, 10:50 AM
Hello

I'm trying to write in some program launchers into 1 programmed .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

ahoodin
April 21st, 2009, 11:15 AM
Well this problem is by design.

You need to call it a different way.

the best way as was mentioned by other members was createprocess().

then there is winexec().

By the way what you are doing is called cross-posting and is most annoying to the list members who are trying to help you. It is considered rude.

Panarchy
April 21st, 2009, 04:32 PM
Thanks, I'm trying them but I keep getting errors.

Can you please give me the context of the code?

(the code before I start opening programs with winexec or createprocess)

Thanks in advance,

Panarchy

Panarchy
April 22nd, 2009, 01:01 AM
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.

Panarchy
April 22nd, 2009, 04:39 AM
I've been able to get it more than 80% complete.

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

Panarchy
April 22nd, 2009, 07:57 AM
Hello Everyone.

Thanks for all your help over the topics.

Here's an update;

I fixed the command-prompt window from appearing by installing Code::Blocks on an XP virtual machine, creating a new project (Win32 GUI) with Dialogue Based (or something).
As far as I can tell, all this added was a #include "resource.h" line.

I have also gotten the %programfiles% thing fixed up as well.

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

#ifdef UNICODE
#define tcout wcout
#else
#define tcout cout
#endif

int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE hprevious, LPSTR cmdline, int cmdshow) {

STARTUPINFO si = {0};
PROCESS_INFORMATION pi = {0};
TCHAR lpCmdLine[MAX_PATH] = {0};
::ExpandEnvironmentStrings(_T("\"%ProgramFiles%\\Symantec\\LiveUpdate\\LUALL.exe\""),
lpCmdLine, MAX_PATH);

std::tcout << _T("Command line : ") << lpCmdLine << std::endl;

BOOL bRet = ::CreateProcess(NULL, lpCmdLine, NULL, NULL, FALSE,
CREATE_NO_WINDOW, NULL, NULL, &si, &pi);

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;
}

:D

Works perfectly now.

One final question, how do I give the program an icon within Code::Blocks?

Please reply.

Thanks in advance,

Panarchy

Panarchy
April 22nd, 2009, 04:33 PM
The first icon in your resource file will be used as the icon of the executable. You'll have to create your resource file manually though, AFAIK Code::Blocks does not have a dialog for it like Dev-cpp. It's not extremely hard, just put something like this in it:
MY_ICON ICON "my_icon.ico"
The first word is the name of the icon (not important unless you want to refer to it in your code), the second word indicates it's an icon and then comes the name of the file to use.


8)

That worked for me!

SWEET - My project has been perfected!