How-To Stop Command-Prompt Window from appearing?

Panarchy's Avatar, Join Date: Nov 2007
Contributor
Hello

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

Here is my code;

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
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Build it as a Windows application instead and use WinMain instead of main.
0
Panarchy's Avatar, Join Date: Nov 2007
Contributor
Thanks

Trying to work out how to do that, and failing

Please give me a code example.

Thanks in advance,

Panarchy
0
Panarchy's Avatar, Join Date: Nov 2007
Contributor
Hello

I got it to work pretty much perfectly now!



Code:
#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.

Last edited by Panarchy; 22Apr2009 at 12:20..
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Have you checked the %ProgramFiles% is expanded correctly? To try this you could copy notepad.exe to the programfiles directory then launch "%ProgramFiles%\notepad.exe".
0
Panarchy's Avatar, Join Date: Nov 2007
Contributor
Will do.
0
Panarchy's Avatar, Join Date: Nov 2007
Contributor
It didn't work

Here is the exact code I have;

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?

This works, however shows the command-prompt window (until it exits);
Code:
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
0
Panarchy's Avatar, Join Date: Nov 2007
Contributor
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.

Code:
#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;
}


Works perfectly now.

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

Please reply.

Thanks in advance,

Panarchy

Last edited by Panarchy; 22Apr2009 at 18:22..
0
Panarchy's Avatar, Join Date: Nov 2007
Contributor
[quote author=Urxae link=topic=991.msg6837#msg6837 date=1128033880]
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:
Code:
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.
[/quote]

8)

That worked for me!

SWEET - My project has been perfected!