what can I use to open up a program on windows.... like say... when I run the program it opens up msn?
Alvin
what can I use to open up a program on windows.... like say... when I run the program it opens up msn?
Alvin
System("X:\path\to\exe\folder\file.xxx")
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?
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....
and there are two errors when I hit the build button.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; }
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...
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.
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: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.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 }
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 02: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
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
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)Originally Posted by CornedBee
@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 02: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
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.Originally Posted by major_small
Meg: Everybody! Guess what I am?
Stewie: Hm, the end result of a drunken back-seat grope-fest and a broken prophylactic?
or you can use ShellExecute()
why not?Originally Posted by dan20n
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.
and the test.exe source:Code:#include<iostream> #include<fstream> int main() { char ch; char key[]="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[i]; //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; }a few notes:Code:#include<iostream> int main() { std::cout<<"Hello World"; std::cin.get(); return 0; }
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 03: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
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
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...Originally Posted by CornedBee
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
But if he's the only one, what the use of the thing in the first place?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...
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
you've never done things like that before when you just started programming?Originally Posted by CornedBee
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