Click here to Skip to main content
15,881,640 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to start my application on start up of windows.
For that i have used
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run registry value
and it worked correct.

But now i want to set the registry value from c# code
but i cann't edit or add new value in registry programtically.
can u say how to do this???
Posted

If you are trying to write to HKLM, make sure that you have admin privileges. If not the registry write attempt will fail. I suspect that you are manually adding the value from one (admin) username and trying to run your program from another (non-admin) username.
 
Share this answer
 
Comments
Hetal Jariwala 2-Jan-13 23:10pm    
I have done it manually and it worked perfectly.
But when i'm trying to do this from c# it is not changing at all.
H.Brydon 3-Jan-13 0:00am    
Reading or writing anything in the registry from code requires multiple steps. Each of these steps gives you a return code. Make sure you look at every return code and make sure you have success at each step.
You can add a shortcut of the program to the startup folder in the start menu, that should start your program everytime you start the OS.
 
Share this answer
 
Comments
Hetal Jariwala 2-Jan-13 23:09pm    
But by that way operator can easily remove program from startup
You need to use the resgitry class to access (read or write) registry values.

http://msdn.microsoft.com/en-us/library/5f1xf5kf.aspx[^]

Look at this article to get a heads up:

http://www.switchonthecode.com/tutorials/csharp-snippet-tutorial-editing-the-windows-registry[^]
 
Share this answer
 
Comments
Hetal Jariwala 2-Jan-13 3:20am    
I have written this way but i cann't access the LOCAL_MACHINE assembly....
Hetal Jariwala 2-Jan-13 3:20am    
How to solve this??
Hi,

Here you read how to read, write and delete from registry:
Read, write and delete from registry with C#[^]
Another way to start an application automatically, is to create a shortcut to your application in the Startup folder:
Run C# application on user logon (Windows Forms)[^]
 
Share this answer
 
Comments
Hetal Jariwala 2-Jan-13 3:20am    
I have written this way but i cann't access the LOCAL_MACHINE assembly....
Hetal Jariwala 2-Jan-13 3:20am    
How to solve this??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900