| |
| Posted by rumbu in reply to Dicebot | PermalinkReply |
|
rumbu
Posted in reply to Dicebot
| 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.
|