Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

system() function

I was wondering if anyone knows a way to use the system function (or any function that would be like entering a command in the DOS prompt) from a Windows application and not have it bring up DOS prompt while the command is executing? If it makes a difference, the application is probably only going to be used on computers with Win98.



Thanks in advance,

Justin


Comments

  • Yes there is, it's called Console Applications. There are a bunch of API's for a

    console app (i.e. WriteConsole, ect.).



    You can get there structions in the Win32 Programmers Reference. I'm assuming

    that you do not have it, otherwise, you probally wouldn't have asked that question.



    Hope that helped,

    *unknown*



    P.S. I included a link that will download it for you. It's about 5 megs.


    URL:http://www.multimania.com/crimstuff/win32.zip

  • I guess my question wasn't very clear. What I am trying to do is get a GUI Windows application (one that normaly uses WinMain as opposed to main) to use the system function without displaying a console window. I've also already tried using the Windows API console functions, but whenever I call AllocConsole, it shows the console window too.



    Justin


  • Hello Justin,



    I have no compiler in this machine (I installed Visual Studio 7 beta over VC++ 5.0 and neither is working :) but what would happen if you run a console app with CreateProcess with SW_HIDE? You can easily get the console window handle with EnumThreadWindows maybe and WM_CLOSE or DestroyWindow it.



    If that works, then maybe you can write a simple console app that receives the actual "dos" command through the command line and run that.



    Just a thought.



    : I guess my question wasn't very clear. What I am trying to do is get a GUI Windows application (one that normaly uses WinMain as opposed to main) to use the system function without displaying a console window. I've also already tried using the Windows API console functions, but whenever I call AllocConsole, it shows the console window too.

    :

    : Justin

    :






  • You can specify the CREATE_NO_WINDOW flag in CreateProcess under Windows NT. The DETACHED_PROCESS flag may also have the same effect, and would be more portable.



    Sunlight


  • Greetings

    I could be way of base, but... I recently wrote a

    dialog based GUI loader for Win2k SP1 to handle all the commandline switches etc. useing the ShellExecute() function with seperate buffers for the target .exe & commandline switches. if you think it might help I'll Email the source/project file to you.



    Stoic Joker



    : I was wondering if anyone knows a way to use the system function (or any function that would be like entering a command in the DOS prompt) from a Windows application and not have it bring up DOS prompt while the command is executing? If it makes a difference, the application is probably only going to be used on computers with Win98.

    :

    : Thanks in advance,

    : Justin

    :






  • Thanks to everyone who replied, I've gotten it working now. I ended up using KMS's method of calling CreateProcess using SW_HIDE in the STARTUPINFO paramiter to execute a console app I wrote that passes its command line to the system() function.



    My biggest problem was waiting for the command to complete before doing anything else, which I finally got done by waiting for GetExitCodeProcess to stop giving me STILL_ACTIVE in a while loop. I didn't seem to need to use EnumThreadWindows or DestroyWindow, it seems the console app automatically closes when it finishes executing.



    Thanks Again,

    Justin


  • Christinme7890Christinme7890 Posts: 6Member
    : I was wondering if anyone knows a way to use the system function (or any function that would be like entering a command in the DOS prompt) from a Windows application and not have it bring up DOS prompt while the command is executing? If it makes a difference, the application is probably only going to be used on computers with Win98.
    :
    : Thanks in advance,
    : Justin
    :
    :
    the system function should work. you need to include dos.h and the system function arguements are just a string. the string is what you want the dos shell to do. the shell does not show or at least should not show.

  • wael_tahonwael_tahon Posts: 65Member
    Use
    #include
    then:
    WinExec("Full path with arguments",SW_HIDDEN);

    Ha ha ha hooooooooooooooo

  • wael_tahonwael_tahon Posts: 65Member
    Take this i try it my self
    (1) from inside your program make a batch file containing all
    the DOS commands you want and name it "c:c.bat"
    use fopen,fwrite,fclose so simple.

    (2) make a new Win32 program and call it "t.exe" and put this code on it.

    #include
    #include
    #include

    int PASCAL WinMain(HINSTANCE hCurInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
    SetWindowLong(/*your App handle*/, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
    system("c:\c.bat");
    return 0;
    }

    (3) Execute this program from inside your main program like this

    WinExec("t.exe",SW_HIDDEN);


    Gooooooooood bye




Sign In or Register to comment.