add program to startup?

how can i add my program to startup?

Page 1 of 1

5 Replies - 17763 Views - Last Post: 22 February 2009 - 10:46 AM Rate Topic: -----

#1 nerox69  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 21-February 09

add program to startup?

Posted 21 February 2009 - 10:43 PM

Can anyone please help/show me how I could start my program when windows starts?
Is This A Good Question/Topic? 0
  • +

Replies To: add program to startup?

#2 nerox69  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 21-February 09

Re: add program to startup?

Posted 21 February 2009 - 11:20 PM

anyone have any information on how I can do this?
Was This Post Helpful? 0
  • +
  • -

#3 nerox69  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 21-February 09

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
Was This Post Helpful? 0
  • +
  • -

#4 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

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
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6092
  • View blog
  • Posts: 23,613
  • Joined: 23-August 08

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:
#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;
}

Was This Post Helpful? 1

#6 nerox69  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 21-February 09

Re: add program to startup?

Posted 22 February 2009 - 10:46 AM

thank you jack, that helped
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1