1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

How-To Stop Command-Prompt Window from appearing?

Discussion in 'C++' started by Panarchy, Apr 21, 2009.

  1. Panarchy

    Panarchy New Member

    Joined:
    Nov 29, 2007
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Build it as a Windows application instead and use WinMain instead of main.
     
  3. Panarchy

    Panarchy New Member

    Joined:
    Nov 29, 2007
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    Thanks

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

    Please give me a code example.

    Thanks in advance,

    Panarchy
     
  4. Panarchy

    Panarchy New Member

    Joined:
    Nov 29, 2007
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
    Last edited: Apr 22, 2009
  5. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    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".
     
  6. Panarchy

    Panarchy New Member

    Joined:
    Nov 29, 2007
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    Will do.
     
  7. Panarchy

    Panarchy New Member

    Joined:
    Nov 29, 2007
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  8. Panarchy

    Panarchy New Member

    Joined:
    Nov 29, 2007
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    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
     
    Last edited: Apr 22, 2009
  9. Panarchy

    Panarchy New Member

    Joined:
    Nov 29, 2007
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    [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!
     

Share This Page