Thread: Executing exe file in c code.

  1. #1
    Registered User
    Join Date
    Apr 2015
    Posts
    42

    Executing exe file in c code.

    Hello,

    I want to write a program that opens itself. For example.

    Code:
    int main() {
        printf("Hello World");
        /***CODE HERE***/
        return 0;
    }
    When I compile this program and execute it, it will open itself again.

    Edit:

    Found a way to do this with
    Code:
    ShellExecuteA(GetDesktopWindow(), "open", "FILE_NAME_HERE", NULL, NULL, SW_SHOW);
    Last edited by Vsky; 04-10-2015 at 09:31 AM.

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Why do you want to do this? It seems like a pretty useless thing for a program to do.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  3. #3
    Registered User
    Join Date
    Apr 2015
    Posts
    42
    Does it really matter It's just for fun actually I like testing stuff.

  4. #4
    Registered User
    Join Date
    Mar 2015
    Location
    BE
    Posts
    66
    Quote Originally Posted by Vsky View Post
    Does it really matter It's just for fun actually I like testing stuff.
    Of course, it does matter. We ask others to share their knowledge with us, so it would be really unfair if we don't do the same when they ask questions.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,664
    > I want to write a program that opens itself. For example.
    Otherwise known as a fork bomb.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Executing Code for as long as
    By CPlus in forum C++ Programming
    Replies: 5
    Last Post: 02-14-2010, 09:51 PM
  2. Why Isent My Code Executing?
    By mike_g in forum C Programming
    Replies: 5
    Last Post: 07-25-2008, 08:50 AM
  3. Giving instruction to an executing C code
    By darkwalk in forum C Programming
    Replies: 2
    Last Post: 10-24-2006, 12:01 PM
  4. Replies: 40
    Last Post: 09-01-2006, 12:09 AM
  5. Executing C++ Code at Runtime
    By jdm in forum C++ Programming
    Replies: 14
    Last Post: 10-18-2004, 05:32 PM