Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

starting a process automatically at logon?

Status
Not open for further replies.

erixire

Technical User
Jun 4, 2002
72
0
0
CA
Hi,

Is there a way to start a process automatically in windows at logon? I remember that a friend showed me a way in C++ programming. He wrote a small program that he put in the startup directory (so that everytime he log into windows it starts automatically) and that program started a process so that we can see it by pressing the Ctrl+Shift+Esc keys in the "processes" tab. If it's possible, can somebody provide me a hint about this (in ANSI C++ if possible)? I know a little bit of C/C++. Thanks
 
if you go to the windows registry under
Software\\Microsoft\\Windows\\CurrentVersion\\Run
you will find the names of the applications that start automatically when windows starts.
you can add an entry for your application at that location
to that programmatically you'll have to use the c++ registry functions.
here's an example:

//define the location
#define RUN_KEY
_T("Software\\Microsoft\\Windows\\CurrentVersion\\Run")

HKEY key;
DWORD size, type, disposition;

//try to open the registry key for writing
if(RegOpenKeyEx(HKEY_CURRENT_USER, RUN_KEY, 0, KEY_WRITE, &key) !=ERROR_SUCCESS)
{
//if it doesn't exist create it
RegCreateKeyEx(HKEY_CURRENT_USER, RUN_KEY,0,_T (""),REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, &disposition);
}

CString Exe=WorkingDirectory+_T("yourApp.exe") ;
type=REG_SZ;
size=Exe.GetLength();
//write yor executable's name in registry
RegSetValueEx(key,_T(&quot;Run&quot;) ,0,type,reinterpret_cast<BYTE*>(Exe.GetBuffer(100)),size*2);


RegCloseKey(key);

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top