Windows programming without command prompt

This is a discussion on Windows programming without command prompt within the C Programming forums, part of the General Programming Boards category; I need to create a simple program to copy a program in the current directory, then execute it. So far, ...

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    1

    Windows programming without command prompt

    I need to create a simple program to copy a program in the current directory, then execute it. So far, it works, I was hoping to have this run on Vista and XP, here is my code:

    Code:
    int main()
    {
        system("copy putty.exe C:\\");
        system("C:\\putty.exe");
        system("exit");
        return 0;
    }
    But, the problem is command prompt keeps poping up when the copying and program executes. How can I stop command prompt from even being shown? I am not sure if this is a C problem, but I am wondering if anyone can help.
    Thanks.
    -ARCKEDA

  2. #2
    ---
    Join Date
    May 2004
    Posts
    1,379
    I'm not so sure you can because the system() function is just that. It calls the console with the parameters inside the " ".

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Use the Win32 API, CopyFile() & CreateProcess()

    http://msdn.microsoft.com/en-us/libr...dz(VS.71).aspx
    According to the page, system() isn't compatible with Vista.
    Last edited by zacs7; 06-04-2008 at 01:20 AM.

  4. #4
    HelpingYouHelpUsHelpUsAll
    Join Date
    Dec 2007
    Location
    In your nightmares
    Posts
    223
    The trick to write a program in windows with no interface is to use the win32 api and don't call ShowWindow(), you could probably even skip a few other things if you wanted to (like the message loop). If you create a simple program using int main() then it will always open up the command prompt. Also suggest thread is more "Windows Programming" than "C programming".
    long time no C; //seige
    You miss 100% of the people you don't C;
    Code:
    if (language != LANG_C && language != LANG_CPP)
        drown(language);

  5. #5
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    If that's all your program is doing, why bother writing a C program for it? Just use a batch file or VB Script...

  6. #6
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by cpjust View Post
    If that's all your program is doing, why bother writing a C program for it? Just use a batch file or VB Script...
    I think a batch file would still open a command prompt window.

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by QuantumPete View Post
    I think a batch file would still open a command prompt window.

    QuantumPete
    But you could do something like "start /min foo.bat" or some such. It will then only appear on the task-bar, but the window doesn't show up.

    --
    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.

  8. #8
    HelpingYouHelpUsHelpUsAll
    Join Date
    Dec 2007
    Location
    In your nightmares
    Posts
    223
    Then, you have to either call it from cmd anyway, make a shortcut to it or win>run it. This method doesn't take long (don't have to register the window) and can be just run any method. C can have advantages to making a bat or vb script (if you don't have what ever is nescary to run vb scripts). I don't know, C could be faster than bat, also C can do more than batch scripts can. This is a different matter with shell scripts on UNIX though. Anyway, it is a good alternative and works (that should be the most improtant thing - it works)
    long time no C; //seige
    You miss 100% of the people you don't C;
    Code:
    if (language != LANG_C && language != LANG_CPP)
        drown(language);

  9. #9
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by P4R4N01D View Post
    Then, you have to either call it from cmd anyway, make a shortcut to it or win>run it. This method doesn't take long (don't have to register the window) and can be just run any method. C can have advantages to making a bat or vb script (if you don't have what ever is nescary to run vb scripts). I don't know, C could be faster than bat, also C can do more than batch scripts can. This is a different matter with shell scripts on UNIX though. Anyway, it is a good alternative and works (that should be the most improtant thing - it works)
    What's wrong with double-clicking on a .bat or .vbs file? It works fine for me.
    Every version of Windows (except maybe Win 95 and below) have VB Script built into it, so no need to install anything, just create a .vbs script and run it.

    I'm not saying C/C++ isn't a billion times more powerful that those scripting languages. I'm just saying for a program that only has 3 platform specific system() commands, a script is easier and faster to write, and no need to recompile when you make a change...

  10. #10
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Or since you're writing windows software -- do it the way MSDN suggests.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Windows 98/2000 programming in Windows XP
    By Bill83 in forum Windows Programming
    Replies: 3
    Last Post: 07-22-2005, 02:16 PM
  2. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 05:48 PM
  3. dual boot Win XP, win 2000
    By Micko in forum Tech Board
    Replies: 6
    Last Post: 05-30-2005, 02:55 PM
  4. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 12:19 AM
  5. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 05:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21