Click here to Skip to main content
12,295,311 members (56,045 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# Windows
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 1-Jan-13 2:11am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  
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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

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.
  Permalink  
Comments
Hetal Jariwala 2-Jan-13 23:09pm
   
But by that way operator can easily remove program from startup
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  
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??
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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)[^]
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160525.2 | Last Updated 2 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100