Solved

Open Program when another Closes

Posted on 2003-11-07
12
225 Views
Last Modified: 2010-04-15
Hello, I have 2 programs written in C, and I want one to open when the other closes.  Can anyone help me out?
0
Comment
Question by:People_Code
  • 6
  • 5
12 Comments
 

Expert Comment

by:rishisk
ID: 9704894
Though I'm not sure of what you want to achieve, you can write a small shell script (in Unix) or a batch file in (Windows) with program B called after program A. Since the order of execution is sequential, you'll get what you want.

0
 

Author Comment

by:People_Code
ID: 9704977
oh man, I never even though of that.  Do you know how to insert the batch file?
0
 

Expert Comment

by:rishisk
ID: 9705033
If you are using windows, try the following:

Create a file called exec_prgs.bat (through notepad) in which you'll type the following (assuming that a.exe and b.exe are the programs to be executed in the order:

a.exe
b.exe

That's it.
0
 

Author Comment

by:People_Code
ID: 9705268
Ok but, how do you put the bat into the C code?
0
 

Expert Comment

by:rishisk
ID: 9705297
You don't need to put the batch file into code. Please send in the C program code. Probably, I can explain you better.
0
 

Author Comment

by:People_Code
ID: 9705337
where to?
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Expert Comment

by:rishisk
ID: 9705362
Paste it here.
0
 

Author Comment

by:People_Code
ID: 9705430
This is program 1.

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<unistd.h>
#include<conio.h>
#define SMALL_STR_LEN 80
#define LARGE_STR_LEN 1024


char name[SMALL_STR_LEN],sel[SMALL_STR_LEN],steal[SMALL_STR_LEN],account[SMALL_STR_LEN],email[SMALL_STR_LEN],web[SMALL_STR_LEN],html_code[LARGE_STR_LEN],crash[SMALL_STR_LEN];
char url[]="//";
int selection,prog_exit;
char *stripweb;

void create_menu(void);
char get_string(char* get_var, int get_len);

int main()
{
  system("color A");

  printf("\n                                 People Code\n");
  printf("\n                                 Version 1.0");
printf("\n           ........ ........ .......... ........ ...       ........");
printf("\n           : .... : : .....: : ...... : : .... : : :       : .....:");
printf("\n           : :  : : : :      : :    : : : :  : : : :       : : ");
printf("\n           : :..: : : :...   : :    : : : :..: : : :       : :...");
printf("\n           : .....: : ...:   : :    : : : .....: : :       : ...:");
printf("\n           : :      : :      : :    : : : :      : :       : :");
printf("\n           : :      : :      : :    : : : :      : :       : :");
printf("\n           : :      : :..... : :....: : : :      : :...... : :.....");
printf("\n           :.:      :......: :........: :.:      :.......: :......:");
printf("\n                    ......... .......... .....    ........");
printf("\n                    : ......: : ...... : : .. :   : .....:");
printf("\n                    : :       : :    : : : : : :  : :");
printf("\n                    : :       : :    : : : :  : : : :...");
printf("\n                    : :       : :    : : : :  : : : ...:");
printf("\n                    : :       : :    : : : :  : : : :");
printf("\n                    : :       : :    : : : : : :  : :");
printf("\nWritten by:         : :...... : :....: : : :. :   : :.....");
printf("\nTyler McCormack     :.......: :........: :...:    :......:");


  printf("\n\n                          Press enter to continue\n");

  getch();


    while(1) {
    create_menu();
    get_string(sel,SMALL_STR_LEN);
    selection = atoi(sel);
    if (selection > 6 || selection < 1) {
      printf("\n\nInvalid Selection, pick somthing from the menu.\n\n");
    }
    else {
      switch(selection) {

      case 1:
      prog_exit=1;
      printf("\nWhat is the ip address of the computer you want to steal files from?\n\n",steal);
      get_string(steal,SMALL_STR_LEN);
      if('\0'== steal[0]) {
        printf("\n\nNull value not allowed\n\n");
        break;
      }
      else {
        printf("\n\nConnecting to %s...\n",steal);
      sleep(5000);
      printf("\n\nConnection Successful\n");
      sleep(1000);
      printf("\n\nWhat is the name of the file you want to steal?\n",name);
      get_string(steal,SMALL_STR_LEN);
      printf("\nSearching for %s...\n\n",steal);
      sleep(6000);
      printf("\nSorry, no %s was found on this computer.\n\n",steal);


      break;

      }
      case 2:
      prog_exit=1;
      printf("What is the name of the Yahoo/Hotmail account you wish to crack? ");
      get_string(account,SMALL_STR_LEN);
      if('\0' == account[0]) {
        printf("\n\nNull value not allowed\n\n");
        break;
      }
      else {
        printf("Is this a (Y)ahoo or (H)otmail account? ");
        get_string(email,SMALL_STR_LEN);
        if(strcmp(email,"Y") == 0 || strcmp(email,"y") == 0) {
          printf("\n\nAttempting to Access %s@yahoo.com...please wait\n",account);
          sleep(5000);
          printf("\n\nConnection to 66.218.71.198\n");
          sleep(3000);
          printf("\n\nConnection Successful\n\n\nAttempting to access list of emails for %s@yahoo.com\n",account);
          sleep(3000);
          printf("\n\nNo E-mails currently found for this user, please try again later\n\n");
          break;
        }
        else if(strcmp(email,"H") == 0 || strcmp(email,"h") == 0) {
          printf("\n\nAttempting to Access %s@hotmail.com...please wait...\n",account);
          sleep(5000);
          printf("\n\nConnection TO 64.4.44.7...\n");
          sleep(3000);
          printf("\n\nConnection Successful\n\n\nAttemping to access list of emails for %s@hotmail.com\n",account);
          sleep(3000);
          printf("\n\nNo E-mails currently found for this user, please try again later.\n\n");
          break;
        }
        else {
          printf("\n\nYou have a choice, Yahoo (Y), or Hotmail (H).  Pick one.\n\n");
          break;
        }
      }
      case 3:
      prog_exit=1;
      printf("\n\nWhat is the website URL that you wish to deface\n");
      get_string(web,SMALL_STR_LEN);
      if('\0' == web[0]) {
        printf("\n\nNull Value Not Allowed\n\n");
        break;
      }
      else {
        stripweb = strstr(web,url);
        if(stripweb) {
          stripweb += strlen(url);
          printf("\n\nAttempting to connect to the url: %s\n",stripweb);
        }
        else {
          printf("\n\nAttempting to connect to the url: %s\n",web);
        }
      }
      sleep(2000);
      printf("\n\nConnection Established\n");
      printf("\n\nEnter the HTML you want for this index file on one line\n");
      get_string(html_code,LARGE_STR_LEN);
      if('\0'== html_code[0])  {
        printf("\n\nNull Value not allowed\n\n");
        break;
      }
      else {
        printf("\n\nAdding the following code to the index file: %s\n",html_code);
        if(strlen(html_code) < 50) {
          sleep(2000);
        }
        else if(strlen(html_code) > 50 && strlen(html_code) < 200) {
          sleep(2000);
        }
        else {
          sleep(2000);
        }
        printf("\n\nUPLOAD COMPLETE! Disconnecting from server\n\n");
        sleep(1000);
        break;
      }

      case 4:
      prog_exit=1;
      printf("\n\nWhat is the ip adress of the pc you would like to crash?\n\n");
      get_string(crash,SMALL_STR_LEN);
      if('\0' == crash[0]) {
        printf("\n\nNull Value Not Allowed\n\n");
        break;
      }
      else {
        printf("\n\nConnection to %s...\n\n",crash);
        sleep(5000);
        printf("\n\nConnection Complete!\n\n");
        sleep(1000);
        printf("\n\nDeleting Windows Explorer...\n\n");
        sleep(4000);
        printf("\n\nExplorer deleted!  Computer Crashed!!!\n\n");
        sleep(1000);
        break;
        }
        case 5:

      if(prog_exit == 0) {
      printf("\n\nThank you using my program that doesn't do anything. If this program did what it says it does, I wouldn't have written it.  Hacking isn't about defacing        websites and cracking email accounts.  It's about learning.  Don't ever deface  websites or crash computers, or anything like that.  All that will do for you   is get you a hefty fine and lots of jail time.%s\n\n",name); {
      system("PAUSE");

      }
      if (strlen(name) <50) {
      }
      }
      return(0);
      }
    }
  }
  return 0;
}
FILE *fp;

if ((fp = fopen("myfile", "r")) ==NULL){
  printf("Error opening file\n");
  exit(1);
}

void create_menu(void) {
  printf("\nPeople Code: MENU\n\n"
       "1) Steal files\n"
       "2) Crack a Yahoo or Hotmail account\n"
     "3) Take down a website\n"
     "4) Crash a PC\n"
     "5) Quit People Code\n\n"
       "SELECTION: ");
}

char get_string(char* get_var, int get_len) {
  char *termcheck;
  memset(get_var, (int)'\0', get_len);
  fgets(get_var,get_len,stdin);
  termcheck = strchr(get_var,'\n');
  if(termcheck != NULL) *termcheck='\0';
  return 15;
}


I want this program (or some kind of pop-up) to come up when you exit program 1.

#include<stdio.h>

int main () {
system("color A");
  printf("\n\nThank you using my program that doesn't do anything. If this program did what it says it does, I wouldn't have written it.  Hacking isn't about defacing        websites and cracking email accounts.  It's about learning.  Don't ever deface   websites or crash a computer, or anything like that.  All that will do for you is get you a hefty fine and lots of jail time.\n\n"); {
  system("PAUSE");
}
  return(0);
}
0
 

Expert Comment

by:rishisk
ID: 9705548
The program 2 is already part of the first program. So why do you want print the message again. Anyway, if that is what you want, compile both programs, then create a text file as mentioned earlier, with the name of the first executable in the first line and name of the second executable in the next line and name it with a .bat extension. Once the batch file is created, in the command prompt, change directory to where you have created the .bat file and type the name of the batch file. This batch file should run the first program. If the user chooses the option 5, the first program will exit. Now the batch file takes the control and moves to the next line and executes the second program, which prints the message.
0
 

Author Comment

by:People_Code
ID: 9705557
well, whenever i exit the program, that message does not show up and i want it to.  any suggestions?
0
 

Expert Comment

by:rishisk
ID: 9705677
Can you paste the exact command you typed in. Make sure both the executbles, the batch file are placed in the same directory.
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 125 total points
ID: 9706125
suppose you want to launch programB when programA is about to exit.
system() function is used to launch program from inside another program
system ("path_to_program_B");
statement when inserted in program A, will launch programB
be warned, programA will not proceed further from this point until programB finishes and returns. If that behaviour is not desirable, then use fork() followed by exec() on *nix machine and CreateProcess() on windows.

Since you talked about launching on exit, you can put all the actions you want to be performed at exit in a function and register that function using atexit(). This registered function would be invoked when your program is about to exit.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now