Got a question

This is a discussion on Got a question within the C++ Programming forums, part of the General Programming Boards category; Is there any way to open a windows file or program through C++?...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    14

    Got a question

    Is there any way to open a windows file or program through C++?

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,062
    Yes. You can use the system() command.

    Code:
    system("notepad");
    It can be a security issue if it's used incorrectly though. For instance, don't let users input whatever they want into a string that is presumable a file they're supposed to open and just throw that into the system command.
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    14
    ok thanx

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    There are other options like ShellExecute or CreateProcess. There is a FAQ entry on running other programs I believe.

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    start automatically opens a document with the default program (like ShellExecute). ie:
    Code:
    system("start hello.c");
    will open hello.c with whatever your IDE for .c files is.

    [edit]
    FAQ entry: http://faq.cprogramming.com/cgi-bin/...&id=1043284392
    [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

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