Jesvin Jose
Jesvin Jose

Reputation: 23078

Windows- C code to make a program run at startup

I am making a C program that, running with admin privileges, makes another .exe (also in C) to run at startup for one/all user(s), in the background. Other answers use .net, but how do I do it in C, developed in minGW?

So

  1. C code which sets a program to run at startup for user

  2. the installed program to run in the background (without opening a terminal)

Yes, I feel it's sufficiently distinct enough to be asked on it's own :-)

Upvotes: 2

Views: 2325

Answers (2)

Sylvain Defresne
Sylvain Defresne

Reputation: 44483

  1. You can have your program register itself in the windows registry to list of program run at startup.

  2. You need to link to the windows subsystem instead of the console subsystem. This can be done by passing the -Wl,-subsystem,windows to gcc when linking your program.

Upvotes: 2

forsvarir
forsvarir

Reputation: 10839

Easy to ask... non-trivial to answer in a code snippet. It looks like you're trying to create a windows service, which involves interacting with the Service Control Manager to register and start the service. You might want to start off by looking at the MSDN site and here and come back when you have more specific questions.

Upvotes: 2

Related Questions