Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run C# Application on Windows Start up

I'm trying to start a few applications for the current user only when Windows starts up.

I can accomplish this with the following:

RegistryKey oKey = Registry.CurrentUser.OpenSubKey("Software", true);
oKey = oKey.OpenSubKey("Microsoft", true);
oKey = oKey.OpenSubKey("Windows", true);
oKey = oKey.OpenSubKey("CurrentVersion", true);
oKey = oKey.OpenSubKey("Run", true);
oKey.SetValue("Application 1", "C:\\path\\to\\ap1.exe");
oKey.SetValue("Application 2", "C:\\path\\to\\ap2.exe");

But I'm trying to run this as part of a Visual Studio Installer Project. I've added my custom action, the program starts like it should, and the installer works great in XP.

In Windows 7, the installer gets elevated privileges, and does everything but insert the entries into the registry for the current user. How ever, it does insert the registry entries when ran as a standalone application (outside of the installer project) and it does not get elevated privileges.

The only thing I can figure is that with the elevated privileges, it's trying to insert the entries into the Administrators account instead of the current user? or is there something else I'm missing? and is there another way I can achieve my goal here?

like image 731
C0NFUS3D Avatar asked Aug 27 '12 17:08

C0NFUS3D


People also ask

What is run in C?

To run a program written in the C programming language, you need to translate its source code into executable code. This is done with the help of a compiler. Compiler is a program that translates a source file into an executable file. A compiler is a translator.

Can Windows run C?

Two options. Great, now that Visual Studio Community is installed, you have two options for developing and running C programs on Windows. The first option involves using any text editor you like to write your source code, and using the "cl" command within the Developer Command Prompt to compile your code.


1 Answers

Is there a reason to not use the startup folder for the user?

More than likely the problem is the user the installer is executing under. If the user isn't the admin the elevated installer will run under the context of the user who elevated the process.

It would be a safer choice to add your application to the startup folder or to add the registry key on first launch.

like image 84
Frazell Thomas Avatar answered Oct 01 '22 15:10

Frazell Thomas