Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   How-To Stop Command-Prompt Window from appearing? (http://www.go4expert.com/forums/stop-command-prompt-window-appearing-t17020/)

Panarchy 21Apr2009 21:01

How-To Stop Command-Prompt Window from appearing?
 
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

xpi0t0s 21Apr2009 21:21

Re: How-To Stop Command-Prompt Window from appearing?
 
Build it as a Windows application instead and use WinMain instead of main.

Panarchy 22Apr2009 02:42

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

Trying to work out how to do that, and failing :cryin:

Please give me a code example.

Thanks in advance,

Panarchy

Panarchy 22Apr2009 11:17

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

I got it to work pretty much perfectly now!

:D

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.

xpi0t0s 22Apr2009 12:01

Re: How-To Stop Command-Prompt Window from appearing?
 
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".

Panarchy 22Apr2009 12:21

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

Panarchy 22Apr2009 14:55

Re: How-To Stop Command-Prompt Window from appearing?
 
It didn't work :cuss:

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

Panarchy 22Apr2009 18:13

Re: How-To Stop Command-Prompt Window from appearing?
 
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;
}

: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 23Apr2009 02:49

Re: How-To Stop Command-Prompt Window from appearing?
 
[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!


All times are GMT +5.5. The time now is 06:21.