executing files

This is a discussion on executing files within the C++ Programming forums, part of the General Programming Boards category; i have a lot of games. so it is very difficult to search the exe files . so is it ...

  1. #1
    C++Pandit
    Join Date
    Jul 2008
    Posts
    49

    executing files

    i have a lot of games. so it is very difficult to search the exe files . so is it possible to write a program to execute a file

    rgds
    saimadhav

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, it most likely can be done. However, what do you ACTUALLY want to do? Search for a .exe file by name and then execute it, or something else?



    --
    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
    C++Pandit
    Join Date
    Jul 2008
    Posts
    49
    no..

    imagine i already know where the exe`s are located . i would like to make a program that will execute these exe`s on my inputs

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Saimadhav View Post
    no..

    imagine i already know where the exe`s are located . i would like to make a program that will execute these exe`s on my inputs
    You mean like pressing "Window + R" and typing in the path and filename? Or opening a command prompt and typing in the path and the filename? There is no need for any code writing if you already know where the executable is located.

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

  5. #5
    C++Pandit
    Join Date
    Jul 2008
    Posts
    49
    i want the code in c++ that would execute a file
    for ex;
    Code:
    main()
    {
       char game;
       cout<<"Enter game";
       cin>>game;
    
      if (game==GTA)
    {
        }
    what should the code be after
    Code:
    if (game==gta)

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Seems like what you want is a table of which game is where. You can do it like you describ, but game should probably be a std::string, and you would want quotes around "GTA".

    Then you call "ShellExecute()" [or system()] with the path to the game.

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

  7. #7
    C++Pandit
    Join Date
    Jul 2008
    Posts
    49
    could you give an example?

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Saimadhav View Post
    could you give an example?
    I could, but you will learn 100 times more by doing than by copying.

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

  9. #9
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    This is a perfect job for a scripting language.

  10. #10
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Isn't that what the start menu is for?
    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

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by CornedBee View Post
    Isn't that what the start menu is for?
    As I stated in #4 above.

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

  12. #12
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Yes, but I'm thinking of the actual hierarchical menu, not starting a Run dialog or a command prompt.

    In my Windows installation, I've completely reorganized my Programs submenu. Now there's "Games", "Programming", "Background", "Drivers & Co" and "Other".

    Of course, systems where there's no company ego dictating things, such a sane categorization is done by default (hint: Linux desktops). It's only on Windows that anyone thinks that finding a program in CompanyName -> ProductName -> ProductName is normal.
    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

  13. #13
    C++Pandit
    Join Date
    Jul 2008
    Posts
    49

    Talking

    ya i know why there is a start menu! i am asking how do u execute a file by programming in c++?

  14. #14
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Saimadhav View Post
    ya i know why there is a start menu! i am asking how do u execute a file by programming in c++?
    You use, as I explained earlier, ShellExecute() or system(). The former is a Windows API call, which isn't exactly simple, the second just takes a string of something the computer will hopefully be able to execute - if it's wrong, there will be a return code to explain what went wrong.

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

  15. #15
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,534
    If your executing ONLY programs, then use CreateProcess(), and you don't need an example, instructions on using the function are here.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading .dat files from a folder in current directory...
    By porsche911nfs in forum C++ Programming
    Replies: 7
    Last Post: 04-04-2009, 09:52 PM
  2. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 10:46 AM
  3. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 01:41 PM
  4. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM
  5. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM

Tags for this Thread


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