running an external exe file

This is a discussion on running an external exe file within the C++ Programming forums, part of the General Programming Boards category; Hi all, When my program starts i want it to run notepad so notepad suddenly appears on the screen. I ...

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    100

    running an external exe file

    Hi all,

    When my program starts i want it to run notepad so notepad suddenly appears on the screen. I tried

    LoadLibraryEx("c:/windows/notepad.exe", NULL, NULL);

    but no luck. Any ideas.

    For those of you that know VB then im looking for the c++ equivelant of

    Shell("C:/windows/notepad.exe")

    Thanks

  2. #2
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    Code:
    #include<cstdlib>
    
    
    system("c:\\windows\\notepad.exe");
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  3. #3
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    what if the file is in the same directory as the program but you dont know the exact location?

  4. #4
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    You can sometimes get the directory of the current program from looking at the first entry in argv - though it's more reliable to use functions like the ones provided with the system SDK (in this case - Win32 - and I know it provides a function to find the directory of the current program).

    Since the OS is far more likely to have default directories set up than to actually use "windows" as the system folder, I would just use
    [code]
    system("notepad.exe")
    [code]
    There are plenty of system out there that use "Win95" or "Win98" as the system folder.

    Don't forget to read up on the potential problems that inherently come with the use of system(): http://www.cprogramming.com/tips/sho...ount=30&page=1

  5. #5
    #include<xErath.h> xErath's Avatar
    Join Date
    Jun 2004
    Posts
    722
    Quote Originally Posted by The Brain
    Code:
    #include<cstdlib>
    
    
    system("c:\\windows\\notepad.exe");
    system pops up an annoing command line window...

    Check these references
    http://msdn.microsoft.com/library/de...ateprocess.asp
    http://msdn.microsoft.com/library/de...ellexecute.asp

    a quick note

    if you use CreateProcess mind this
    CreateProcess("app.exe","app.exe arg1 arg2 ...", ... );
    yes, you must include the exe's name on both parameters.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  3. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM
  4. How do I execute an external EXE file
    By Scripter in forum C Programming
    Replies: 1
    Last Post: 11-09-2002, 06:02 AM
  5. running a external file
    By krappykoder in forum C++ Programming
    Replies: 5
    Last Post: 06-14-2002, 07:19 PM

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