Answers
May 19, 2009 - 01:56 PM
Are you wanting to code this or happy to do it manually?
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.
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
Hi Nidhi, I wanted to do this by code (c#). So something like what you're saying, but programming it to happen. I think the registry is best.
May 20, 2009 - 07:36 AM
Do you want to set it globally (all users whoever logs in) or current user?
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
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
I havent validated the regKey being set but considering the path being used, every windows install will have that.
Jun 12, 2009 - 03:13 AM
The question looks to be abandoned by the user who asked it. If no action is taken within 2 days, a Quomon Moderator will consider closing the question and distributing the points.
The Quomon Team
The Quomon Team
Add New Comment