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

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    12

    Question 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

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Use CreateProcess?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    12
    Thanks, that's a great idea.

    Is there any special commands I need to use with CreateProcess, or do I just replace all occurrences of system with CreateProcess?

    If there are other commands that need to be included with CreateProcess in order to stop the Command-Prompt window from appearing, then can you please write up for me how this can be done?

    Thanks in advance,

    Panarchy

  4. #4
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    You've already been told where you can find out about CreateProcess. I'd suggest you follow the links and type it in, or use google. If there's anything you don't understand about it's usage that's fine, but expecting people to do it for you will only lead to the kind of responses you got there.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    CreateProcess won't prevent a console from being created for the launcher process.

    Change your subsystem type to win32 (it's in the linker options; alternatively, start over with a fresh project and don't choose Console Application) and write a WinMain function instead of main.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    This issue has already been resolved by a MVP at CodeGuru

  7. #7
    Registered User
    Join Date
    Apr 2009
    Posts
    12

    Question

    Thanks, however I've tried what's been asked there, to no avail.

    Please recommend me something (with code examples).

    Thanks in advance,

    Panarchy

  8. #8
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    You could always just get a handle on the window and use ShowWindow with the hide parameter... The console will flash up, but it'll hide too.
    Code:
    HWND GetConsoleHwnd(void)  {
      #define MY_BUFSIZE 1024 // Buffer size for console window titles.
      HWND hwndFound;         // This is what is returned to the caller.
      char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated
                                          // WindowTitle.
      char pszOldWindowTitle[MY_BUFSIZE]; // Contains original
                                          // WindowTitle.
    
      // Fetch current window title.
      GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
    
      // Format a "unique" NewWindowTitle.
      wsprintf(pszNewWindowTitle,"%d/%d",
                  GetTickCount(),
                  GetCurrentProcessId());
    
      // Change current window title.
      SetConsoleTitle(pszNewWindowTitle);
    
      // Ensure window title has been updated.
      Sleep(40);
    
      // Look for NewWindowTitle.
      hwndFound=FindWindow(NULL, pszNewWindowTitle);
    
      // Restore original window title.
      SetConsoleTitle(pszOldWindowTitle);
    
      return(hwndFound);
    }
    
     
    int main( void ) { 
      HWND cHwnd = GetConsoleHwnd();
      ShowWindow( cHwnd, SW_HIDE );
      Sleep(1000);
      ShowWindow( cHwnd, SW_SHOW );
      Sleep(1000);
    
      return 0;
    }
    http://support.microsoft.com/kb/124103

  9. #9
    Registered User
    Join Date
    Apr 2009
    Posts
    12
    Thanks, that's not a bad idea.

    Just got to work out how to incorporate the above code you mentioned into my existing code.

    Panarchy

  10. #10
    Registered User
    Join Date
    Apr 2009
    Posts
    12

    Question

    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; 04-22-2009 at 01:04 AM.

  11. #11
    Registered User
    Join Date
    Apr 2009
    Posts
    12

    Exclamation

    Hello

    I've finished over 80% of my program. :trockon:

    Here is my code;

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

  12. #12
    Registered User
    Join Date
    Apr 2009
    Posts
    12

    Post

    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; 04-22-2009 at 07:06 AM.

  13. #13
    Registered User
    Join Date
    Apr 2009
    Posts
    12
    [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!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating a child window
    By rakan in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2007, 03:22 PM
  2. Adding buttons, edit boxes, etc to the window
    By rainmanddw in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2006, 03:07 PM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  4. dont want to use all params
    By stallion in forum Windows Programming
    Replies: 2
    Last Post: 02-18-2003, 08:10 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM