Can anyone please help/show me how I could start my program when windows starts?
add program to startup?how can i add my program to startup?
Page 1 of 1
5 Replies - 12615 Views - Last Post: 22 February 2009 - 10:46 AM
Replies To: add program to startup?
#2
Re: add program to startup?
Posted 21 February 2009 - 11:20 PM
anyone have any information on how I can do this?
#3
Re: add program to startup?
Posted 22 February 2009 - 12:19 AM
int main(void)
{
TCHAR szPath[MAX_PATH];
GetModuleFileName(NULL,szPath,MAX_PATH);
HKEY newValue;
RegOpenKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",&newValue);
RegSetValueEx(newValue,"name_me",0,REG_SZ,(LPBYTE)szPath,sizeof(szPath));
RegCloseKey(newValue);
return 0;
}
hope this helps somebodyelse
#4
Re: add program to startup?
Posted 22 February 2009 - 12:29 AM
What you basically need to do is add your program path to Software\Microsoft\Windows\CurrentVersion\Run Key of HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER.
If you want your application to start for all users, place it in HKEY_LOCAL_MACHINE or if you wish to start the application for the current user ONLY, add the program path in HKEY_CURRENT_USER
If you want your application to start for all users, place it in HKEY_LOCAL_MACHINE or if you wish to start the application for the current user ONLY, add the program path in HKEY_CURRENT_USER
#5
Re: add program to startup?
Posted 22 February 2009 - 08:33 AM
Note that adding registry keys under the HKEY_LOCAL_MACHINE hive requires Administrative privileges.
Your program is not quite correct. A better example with error checking would be:
Your program is not quite correct. A better example with error checking would be:
#include <tchar.h>
#include <stdio.h>
#include <windows.h>
int main(void)
{
TCHAR szPath[MAX_PATH];
DWORD pathLen = 0;
// GetModuleFileName returns the number of characters
// written to the array.
pathLen = GetModuleFileName(NULL, szPath, MAX_PATH);
if (pathLen == 0)
{
_tprintf(TEXT("Unable to get module file name; last error = %lu\n"), GetLastError());
return -1;
}
HKEY newValue;
if (RegOpenKey(HKEY_LOCAL_MACHINE,
TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Run"),
&newValue) != ERROR_SUCCESS)
{
_tprintf(TEXT("Unable to open registry key; last error = %lu\n"), GetLastError());
return -1;
}
// Need to pass the length of the path string in bytes,
// which may not equal the number of characters due to
// character set.
DWORD pathLenInBytes = pathLen * sizeof(*szPath);
if (RegSetValueEx(newValue,
TEXT("name_me"),
0,
REG_SZ,
(LPBYTE)szPath,
pathLenInBytes) != ERROR_SUCCESS)
{
RegCloseKey(newValue);
_tprintf(TEXT("Unable to set registry value; last error = %lu\n"), GetLastError());
return -1;
}
RegCloseKey(newValue);
return 0;
}
#6
Re: add program to startup?
Posted 22 February 2009 - 10:46 AM
thank you jack, that helped
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|