Answers
May 19, 2009 - 01:56 PM
Basically one of three places
A shortcut in the StartUp directory (under documents and settings I think it is)
Registry entry HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER
Software\Microsoft\Windows\CurrentVersion\Run
Can be coded as well, but dont know what u want to do.
May 20, 2009 - 04:22 AM
May 20, 2009 - 07:36 AM
This is for all users. Ive added comments so hopefully thats enough for you to understand.
You need to use Win32 namespace i.e. using Microsoft.Win32;
Then here is sample code that creates a key called DustPuppy with a value of "C:\Quomon\DustPuppy.exe"
// ADD THE FOLLOWNIG TO STARTUP - Key=DustPuppy Value="C:\Quomon\DustPuppy.exe"
const string MYKEY = "DustPuppy";
try
{
// Attempt to open the key
RegistryKey regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\
\Run", true);
Object sKey = regKey.GetValue(MYKEY);
// Check if value returned
if (sKey == null)
{
// Value not returned therefore create a value
regKey.SetValue(MYKEY, "\"C:\\Quomon\\DustPuppy.Exe\"");
// THIS MESSAGE BOX IS A DIAGNOSTIC. TO TELL YOU IT DOES NOT EXIST
MessageBox.Show ("Value Dont Exist");
// Now try read it. This is just to confirm we have written to it, if we have
sKey = regKey.GetValue(MYKEY);
}
// Check key read from registry is st
if (sKey == null)
{
MessageBox.Show ("UNABLE TO SET KEY");
}
// DIAGNOSTIC, show result to user
else
{
MessageBox.Show("Value Exists " + sKey);
}
}
catch (Exception ex)
{
MessageBox.Show ("Exception occurred setting key. " + ex.ToString());
}
To use currentusr, change the word SOFTWARE to Software and use CurrentUser instead of LocalMachine after Registry. during opening of subkey
May 20, 2009 - 07:37 AM
Jun 12, 2009 - 03:13 AM
The Quomon Team
Add New Comment