954,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Executing a file at startup?

Hi.

I was wondering about how you might go about executing a file as you log in to your account. For instance, I want to run a file that prompts the user of the date, and any other information as you log-in. Might I need a registry entry or such?
EDIT: I would like this to be performed after a complete restart. i'm using XP


Thanks,

cosmos22
Junior Poster in Training
80 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

use the Scheduled Tasks option in Control Panel

msk88
Newbie Poster
17 posts since Feb 2008
Reputation Points: 10
Solved Threads: 2
 

Use The Scheduled Tasks Option in the Control Panel to start executing the file(program) at startup.

msk88
Newbie Poster
17 posts since Feb 2008
Reputation Points: 10
Solved Threads: 2
 

What happnens if I want to execute this on another computer, which hasn't got this enabled? What should I do then?

cosmos22
Junior Poster in Training
80 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

just throw the file in the startup folder. or make a shortcut to your executable in the startup folder.

(The startup folder is located in the start menu: C:\Documents and Settings\All Users\Start Menu\Programs\Startup)

prushik
Junior Poster
101 posts since Oct 2007
Reputation Points: 61
Solved Threads: 5
 

Ok, so how would I copy the file across to the folder using code?

Thanks

cosmos22
Junior Poster in Training
80 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

You could use system("copy ...") you can find the name of the executable within your code also: argv[0]

prushik
Junior Poster
101 posts since Oct 2007
Reputation Points: 61
Solved Threads: 5
 

What does argv[0] do? And where should I use it? Also, what declaration do you need for a system command?

cosmos22
Junior Poster in Training
80 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

argv[0] is command line argument #0 when your program is run. It is always the name of your executable. If you use that you should be able to copy your file to a new location without hard-coding the file name into your program.
And you shouldn't need to declare anything for system. I assume that you have included iostream, yes?

alternatively you could open the executable as a stream and write that to a new file. However, that is more complicated.

prushik
Junior Poster
101 posts since Oct 2007
Reputation Points: 61
Solved Threads: 5
 

Do you have any coding I could use to carry out a simple task of copying the .exe into the startup folder?

Thanks

cosmos22
Junior Poster in Training
80 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

use the schtasks command to setup the program to be executed at startup.

msk88
Newbie Poster
17 posts since Feb 2008
Reputation Points: 10
Solved Threads: 2
 

You know, cosmos22, playing around with another person's computer really isn't funny. In fact, it is the kind of crap warez dorks and wannabes do.

Why don't you do something that will be both appreciated and cool?

Like write a simple video game.
Or write a cool screen saver you and your friends can use.

Both of these are impressive tasks.

Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
 

the syntax for schtasks command is--

Schtasks /change /tn TaskName [/s Computer [/u [Domain\]User [/p
Password]]] [/ru {[Domain\]User | System}] [/rp Password] [/tr TaskRun] [/st
StartTime] [/ri Interval] [{/et EndTime | /du Duration} [/k]] [/sd StartDate]
[/ed EndDate] [/{ENABLE | DISABLE}] [/it] [/z]

msk88
Newbie Poster
17 posts since Feb 2008
Reputation Points: 10
Solved Threads: 2
 

Maybe cosmos22 does not have a malicious intent. There are legitimate reasons to execute a file on startup. I've certainly done it before.

prushik
Junior Poster
101 posts since Oct 2007
Reputation Points: 61
Solved Threads: 5
 

I didn't say he had malicious intent. (In fact I don't really think he does.)

What I said was he'd have more fun doing something constructive.

Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
 

I certainly don't intend on releasing my code in any way, I purely do it for educational purposes, for my own interests. I'm not stupid enough to release these files over the internet.

prushik, you say you've done this sort of thing before, could I please take a look at an example of your source code, as I'm still not sure.

Thanks

EDIT oh, and Duoas, I have written several flash based room escape style games before. I have also made money from sponsorship for each one.

cosmos22
Junior Poster in Training
80 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

If you are still interested, here is working code, I just wrote it.

#include <cstdlib>
#include <cstdio>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    char cp[500]; 
    sprintf(cp, "copy %s \"C:\\Documents and Settings\\All Users\\Start Menu\\Programs\\Startup\\\"", argv[0]);
    system(cp);
    
    system("PAUSE");
    return EXIT_SUCCESS;
}
What I said was he'd have more fun doing something constructive.


My point was, maybe his purposes are constructive, you don't know. I wrote useful programs that do similar things.

prushik
Junior Poster
101 posts since Oct 2007
Reputation Points: 61
Solved Threads: 5
 

Thank you, I will test it out now. :) I'll let you know quickly if I come across an error... And yes, I have only constructive purposes alongside my programs.

cosmos22
Junior Poster in Training
80 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

Oh, by the way cosmos22: It would be a good idea to check to make sure that your file is not already in the startup folder before copying. You wouldn't want to try to copy the file every time you start up your computer or log on.

prushik
Junior Poster
101 posts since Oct 2007
Reputation Points: 61
Solved Threads: 5
 

Wow, it works brilliantly. Thank you! :)
From then on, when you boot the computer up, will it run the program?
For instance, if I made a program that displayed a message saying "Hello" that was inside the folder, it would boot it up?

Thanks again, :)

cosmos22
Junior Poster in Training
80 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You