Thread: Opening Programs.

  1. #1
    Unregistered
    Guest

    Opening Programs.

    I'm writing a password program to keep people out of my stuff who share this computer, and I need to know how you open another program from another. For example, I need my game, Red Alert 2, to come up when I put in the pass. How would I do this?

  2. #2
    Unregistered
    Guest
    Its very easy. I assume you know how to write a password checker, so when the password is correct, use the ShellExecute API to run the red alert exe.

  3. #3
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Check the FAQ.

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    194
    use "system( char * )"
    system("C:\\path\\redalert2.exe");

    If your trying to secure your computer, that should be a job of the operating system. I know there are programs out there, that can encrypt part of your hard drive, and they will only be un encryped with a password, that may be more effective, than your program

  5. #5
    Unregistered
    Guest
    Doesn't worK:
    C:\Dev-C++\Untitled1.cpp: In function `int main()':
    C:\Dev-C++\Untitled1.cpp:34: unknown escape sequence `\G'

    C:\Dev-C++\Untitled1.cpp:34: unknown escape sequence `\W'
    C:\Dev-C++\Untitled1.cpp:34: unknown escape sequence `\C'
    C:\Dev-C++\Untitled1.cpp:34: unknown escape sequence `\R'

    Execution terminated

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by Unregistered
    Doesn't worK:
    C:\Dev-C++\Untitled1.cpp: In function `int main()':
    C:\Dev-C++\Untitled1.cpp:34: unknown escape sequence `\G'

    C:\Dev-C++\Untitled1.cpp:34: unknown escape sequence `\W'
    C:\Dev-C++\Untitled1.cpp:34: unknown escape sequence `\C'
    C:\Dev-C++\Untitled1.cpp:34: unknown escape sequence `\R'

    Execution terminated
    Are you using a single backslash, or are you using 2? Should be 2 if you want to represent a directory structure/filename. As in the earlier example.

    Post code if this doesn't help.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    include conio.h and link to conio.o

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by Quantrizi
    include conio.h and link to conio.o
    system() lives in stdlib.h
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  9. #9
    Unregistered
    Guest
    Phew, finally got it working. But there is one feature I can't figure out. I want to get it to record whenever someone tries to get into the applications, as you can see in the code. Any ideas why it isn't working? Feel free to make modifications and use it yourselves, by the way, just don't take out the first couple lines of comments. I may make an editor for it and dsitribute it.

    #include <stdlib.h>
    #include <iostream.h>
    #include <string.h>
    #include <time.h>
    #include <process.h>
    #include <fstream.h>

    char password[50];
    char passin[50];
    int prog;

    int main(void)
    {
    ofstream log("accesslog.txt,ios::app");
    time_t rawtime;
    time ( &rawtime );
    log<<"Attempted access on: %s "<<ctime(&rawtime)<<".\n";
    log.close();

    int select;

    srand (time(NULL) );
    select = rand()%8;

    if (select==0)
    strcpy (password,"jeff");

    if (select==1)
    strcpy (password,"ssgnxf");

    if (select==2)
    strcpy (password,"junior");
    if (select==3)
    strcpy (password,"sden");
    if (select==4)
    strcpy (password,"matt_pants");
    if (select==5)
    strcpy (password,"fern");
    if (select==6)
    strcpy (password,"wifey");
    if (select==7)
    strcpy (password,"it_tastes_like");
    if (select==8)
    strcpy (password,"chicken");

    do {
    cout << "Please enter the correct password.\n";
    cin >> passin;
    } while (strcmp (passin,password) != 0);
    cout<<"Confirmed. You are cleared to enter.\n";
    cout<<"\nWhich program would you like to run?\n1. Command and Conquer: Red Alert 2\n2. Nothing.\n\n";
    cin>>prog;
    if(prog==1)
    {
    system("D:\\Games\\Westwood\\CnC\\Ra22.exe");
    }
    if(prog==2)
    {
    return 0;
    }
    }

  10. #10
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    try this.

    Code:
    #include <stdlib.h>
    #include <iostream.h>
    #include <string.h>
    #include <time.h> 
    #include <process.h>
    #include <fstream.h>
    
    char password[50];
    char passin[50];
    int prog;
    
    int main(void)
    {
      ofstream log("accesslog.txt,ios::app");
      time_t rawtime;
      time ( &rawtime );
      log<<"Attempted access on: %s "<<ctime(&rawtime)<<".\n";
      log.close();
    
      int select;
    
      srand (time(NULL) );
      select = rand()%8;
    
      switch(select)
      {
        case 0: strcpy (password,"jeff");break;
        case 1: strcpy (password,"ssgnxf");break;
        case 2: strcpy (password,"junior");break;
        case 3: strcpy (password,"sden");break;
        case 4: strcpy (password,"matt_pants");break;
        case 5: strcpy (password,"fern");break;
        case 6: strcpy (password,"wifey");break;
        case 7: strcpy (password,"it_tastes_like");break;
        case 8: strcpy (password,"chicken");
      }
    
      do{
        cout << "Please enter the correct password.\n";
        cin >> passin;
      }while (strcmp (passin,password) != 0);
    
      cout << "Confirmed. You are cleared to enter.\n\nWhich program would you like"
           << "to run?\n1. Command and Conquer: Red Alert 2\n2. Nothing.\n\n";
    
      cin >> prog;
    
      if(prog==1)
        system("D:\\Games\\Westwood\\CnC\\Ra22.exe");
      else
        return 0;
    }

  11. #11
    Unregistered
    Guest
    Thanks, that's much better organized. However, it still doesn't make a log file that I can use to see when people tried to get into the game. Any ideas here?

  12. #12
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    >>However, it still doesn't make a log file that I can use to see when people tried to get into the game. Any ideas here?

    The log file would probably be made in the folder where you are executing/creating the programs.
    eg-> "C:\PROGRAMMING\C++" and not in the folder where the game is.
    -

  13. #13
    Registered User
    Join Date
    Dec 2001
    Posts
    194
    change
    ofstream log("accesslog.txt,ios::app"); to this
    ofstream log("accesslog.txt" , ios::app);

  14. #14
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Hard coding passwords like you have done is bad practice, I'm afraid. Anyone can hexdump your program and find out your passwords. Try encrpyting them a bit within your source.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. POSIX/DOS programs?
    By nickname_changed in forum C++ Programming
    Replies: 1
    Last Post: 02-28-2003, 05:42 AM
  2. Programs opening programs
    By LinuxPLC in forum C Programming
    Replies: 1
    Last Post: 11-21-2002, 12:50 PM
  3. executing c++ programs on the web
    By gulti01 in forum C++ Programming
    Replies: 4
    Last Post: 08-12-2002, 03:12 AM
  4. Opening other programs from a program
    By Waldo2k2 in forum Windows Programming
    Replies: 2
    Last Post: 06-02-2002, 06:01 PM
  5. Opening programs through a network
    By canine in forum Windows Programming
    Replies: 2
    Last Post: 11-22-2001, 11:12 PM