Opening a Windows program

This is a discussion on Opening a Windows program within the C++ Programming forums, part of the General Programming Boards category; what can I use to open up a program on windows.... like say... when I run the program it opens ...

  1. #1
    Novice Programmer Pyroteh's Avatar
    Join Date
    Jan 2005
    Location
    Alaska
    Posts
    82

    Question Opening a Windows program

    what can I use to open up a program on windows.... like say... when I run the program it opens up msn?

    Alvin

  2. #2
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    System("X:\path\to\exe\folder\file.xxx")

  3. #3
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Make sure you use a lowercase, 's' - C is case-sensitive, and you'll find the function in cstdio.

    Simply put, system() takes a pointer to a C-style string (or a string literal, as above) as a parameter and executes that string as a command in the OS shell. Just be aware of the dangers of using it. What if the program isn't there? What if you're on a different OS? What if the program has been replaced with something else?

  4. #4
    Novice Programmer Pyroteh's Avatar
    Join Date
    Jan 2005
    Location
    Alaska
    Posts
    82
    ok here is what I'm trying to do..... I want to write a program that puts a very simple password on a program..... after I write the program that for the password I'm going to change the name of the windows program that I want to put a password on... then change the program that I write to the name of the windows program... did ya get all that? or is my explanation a little too.... off... HAHA

    so far here is what I have with the program....

    Code:
    #include <iostream>
    #include <string>
    #include <cstdlib>
    using namespace std;
    int main () {
    
    	char password;
    
    	cout << "Enter First Character. " << endl;
    	cin >> password;
    	cin.ignore();
    	
    	if ( password == 'a') {
    
    		char pw;
    
    		cout << "Enter Second Character. " << endl;
    		cin >> pw;
    		cin.ignore();
    
    		if ( pw == 'm' ) {
    			system("C:\location\of\program.xxx");
    	
    		}
    	}
    	cin.get();
    	return 0;
    }
    and there are two errors when I hit the build button.

    fatal error LNK1169: one or more multiply defined symbols found

    and....

    error LNK2005: _main already defined in password.obj

    can anyone help? I know that I can look it up on microsoft.com but I'm kind of running short on time for tonight and the next time I can get on is sunday... :'( so when I get back if there is no reply then I can just look up things and try to figure it out on my own using microsoft.com... and help is greatly appreciated...

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    It means that you have got two copies of the main function in your code. Find the second copy and rename it, delete it or comment it out. Also, remember to double up the back slashes in string literals.

  6. #6
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    so you basically want to hide the real program, and use your program as a sort of gateway to the other program...

    judging from your code, you want a user to have to have to run your program, then type 'a', then type 'm' to get another program to run?

    in that case, you don't need the string library, and here's some fully functional code:
    Code:
    #include<iostream>  //for IO stuff
    #include<cstdlib>   //for exit() and system()
    
    int main()
    {
        char pw;    //it's okay to reuse variables
    
        std::cout<<"Enter the first character: ";   //prompt for input
        std::cin>>pw;       //take in the character
        std::cin.ignore(1); //take in the '\n'
        
        if(pw!='a')     //if the 'password' is wrong
            exit(1);    //exit with a failure code
    
        std::cout<<"Enter the second character: ";  //need input...
        std::cin>>pw;       //take it in
        std::cin.ignore(1); //this one is pretty useless...
        
        if(pw!='m')     //if the second 'password' is wrong
            exit(1);    //exit with a failure code
    
        system("start notepad");    //open a new window to handle notepad
        return 0;                   //exit right after notepad is started
    }
    by the way, this is in NO WAY secure. instead, you might consider encrypting the program you want to run using simple XOR encryption, then when the user enters your program, they have to provide the key (password) that will then (again) be XOR'ed into the original program. then simply have your program run the original. when the original is finished executing, have your program XOR it back to it's useless state.

    of course, keep a backup of this original program, and the method I just suggested is not very secure either, but it is a giant leap in the right direction. especially if you're relying on something as simple as renaming the original program to keep it harder to find...
    Last edited by major_small; 02-10-2005 at 01:52 AM. Reason: Don't write code when you're too tired to write code
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Actually, major_small, given the weird default behaviour of Windows consoles, your code will show the entered password in clear text, and ignore(1) doesn't do what you seem to think it does.
    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

  8. #8
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by CornedBee
    Actually, major_small, given the weird default behaviour of Windows consoles, your code will show the entered password in clear text, and ignore(1) doesn't do what you seem to think it does.
    eh, I never said anything about hiding the text input... and ignore(1) does exactly what I think it does... it's clearing out the '\n' left in the stream by cin (although now that I think about it, it really doesn't matter becaues the program exits right after notepad is opened)

    @Pyroteh: CornedBee does bring up a good point though: the password you put in will be in plain-text and everybody will be able to see what you write, unless you use something like getch() instead of cin.

    edit: I just realized that I used bad wording on my comments of cin.ignore()... fixing that now...
    edit2: wow, that first comment was waaaaay off... I really should be getting myself to sleep now...
    Last edited by major_small; 02-10-2005 at 01:53 AM. Reason: more edits
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  9. #9
    Registered User dan20n's Avatar
    Join Date
    Jan 2005
    Posts
    24
    Quote Originally Posted by major_small
    this is in NO WAY secure. instead, you might consider encrypting the program you want to run using simple XOR encryption, then when the user enters your program, they have to provide the key (password) that will then (again) be XOR'ed into the original program. then simply have your program run the original. when the original is finished executing, have your program XOR it back to it's useless state.
    If i understand correctly, how can you make a portable program that can run on other windows boxes that is safe? Considering you cant really just go grab other applications and encrypt etc that are not yours. Not looking for a step by step guide just maybe rattle off some concepts, searching didnt do me too well here.
    Meg: Everybody! Guess what I am?
    Stewie: Hm, the end result of a drunken back-seat grope-fest and a broken prophylactic?

  10. #10
    Registered User
    Join Date
    Dec 2004
    Location
    The Netherlands
    Posts
    91
    or you can use ShellExecute()

  11. #11
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by dan20n
    Considering you cant really just go grab other applications and encrypt etc that are not yours.
    why not?

    with one run of the following code, you will render test.exe, which is a simple 'hello world' program, utterly useless. with a second run, however, test.exe is restored to it's useable state.

    if you're wondering how it's being done, the following code, in effect, corrupts the target program and then uncorrupts it later on. you can change they key to be any C-style string you want.

    Code:
    #include<iostream>
    #include<fstream>
    
    int main()
    {
        char ch;
        char key&#091;&#093;="Use this as your Password";
        unsigned int index=0;
    
        std::fstream file("test.exe",std::ios::binary|std::ios::in|std::ios::out);
        
        for(;;)
        {
            for(register int i=0;i<strlen(key);i++)
            {
                file.seekg(index,std::ios::beg);
    
                if(file.eof())
                {
                    file.close();
                    return 0;
                }
                    
                file.read(static_cast<char*>(&ch),sizeof(ch));
    
                ch^=key&#091;i&#093;;     //the heart of the XOR encryption
    
                file.seekp(index,std::ios::beg);
                file.write(static_cast<char*>(&ch),sizeof(ch));
    
                ++index;
            }
        }
        
        file.close();
            
        return 0;
    }
    and the test.exe source:
    Code:
    #include<iostream>
    
    int main()
    {
        std::cout<<"Hello World";
        std::cin.get();
        return 0;
    }
    a few notes:

    first, if any moderators deem that this code is malicious, then please feel free to take it down.

    second, this code will take a little while to complete in case you do try to run it (it takes a while to parse the entire file)

    third, please excuse spelling/grammar/coding mistakes... I've been awake way too long...
    Last edited by major_small; 02-10-2005 at 02:39 AM. Reason: a little change here, a little change there, all of a sudden, it's time to scrap and restart.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  12. #12
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    But, major_small, given that ch is just a single character, ignoring one might not suffice.
    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
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by CornedBee
    But, major_small, given that ch is just a single character, ignoring one might not suffice.
    oh, I see what you're saying now... I was thinking more simply, as in he is the only user that will be using this, so he doesn't have to put much effort into user-proofing his code...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  14. #14
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    I was thinking more simply, as in he is the only user that will be using this, so he doesn't have to put much effort into user-proofing his code...
    But if he's the only one, what the use of the thing in the first place?

    If he wants to prevent other users on the same computer from using the program, log in as admin and deny them read/execute on the program directory. Far easier and more secure. Especially as some programs don't react well to being moved away from their installation directory.
    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

  15. #15
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by CornedBee
    But if he's the only one, what the use of the thing in the first place?
    you've never done things like that before when you just started programming?
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 02:30 PM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 11:14 AM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  5. my first windows console program
    By Syneris in forum Windows Programming
    Replies: 3
    Last Post: 04-08-2002, 03:18 PM

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