Thread overview
Run program at startup
Feb 08, 2013
SaltySugar
Feb 08, 2013
Dicebot
Feb 08, 2013
rumbu
Feb 08, 2013
bearophile
February 08, 2013
How to run my program when computer starts?
February 08, 2013
On Friday, 8 February 2013 at 15:06:24 UTC, SaltySugar wrote:
> How to run my program when computer starts?

This question is irrelevant to D and is operating system specific. It is better suited for stackoverflow & Co.
February 08, 2013
On Friday, 8 February 2013 at 15:08:06 UTC, Dicebot wrote:
> On Friday, 8 February 2013 at 15:06:24 UTC, SaltySugar wrote:
>> How to run my program when computer starts?
>
> This question is irrelevant to D and is operating system specific. It is better suited for stackoverflow & Co.

If you want D to become popular, that's not an appropiate answer in the d.learn section. I'm sure that if someone will ask the same thing in the C# section of MSDN will obtain an answer, not a redirect to an external forum.

---

To run at startup for all users, the most used way for a program to do this is to create a string value in the following registry keys:
 - HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Current Version\Run if the program will run every time.
 - HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Current Version\RunOnce if the program will run once.

In D, this will look like this:

import std.windows.registry;


void runMeAtStartupEveryTime(string exeName)
{
	auto key = Registry.localMachine.getKey(`SOFTWARE\Microsoft\Windows\CurrentVersion\Run`, REGSAM.KEY_SET_VALUE);
	key.setValue("runme", exeName);
}


int main(string[] args)
{
	runMeAtStartupEveryTime(args[0]);
	
	return 0;
}

Of course, you must have the appropriate rights to do this. This approach is Windows specific, I don't have any hint about another OS.
February 08, 2013
rumbu:

> If you want D to become popular, that's not an appropiate answer in the d.learn section. I'm sure that if someone will ask the same thing in the C# section of MSDN will obtain an answer, not a redirect to an external forum.

I agree that it's important to be gentle.

(I remember the C newsgroups where many questions received rude answers like: "Not a C Standard question" (because the C standard leaves many essential things to OS-specific functions or compiler-specific implementations)).

Bye,
bearophile