Making a program register itself to run on start up

Hi, I was wondering how I could make a program register itself to run at windows start up. I know how to edit the registry files myself and select programs to run, but how do I make a program register itself first time it is run?
Heres the code I use to install my paperchanger program it shows you how to create and move a shortcut into the startup directory (it should be a simple process to detect if the shortcut already exists). By the way the code is GPL3 so you can use it as you like.

note: processor = 2(64bit), 1(32bit)
osVersion = 5 Windows 2000 and xp , 6 Vista and up

hope this helps
shredded


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
void	install()
{
	_mkdir("C:\\Program Files\\Shredded");
	_mkdir("C:\\Program Files\\Shredded\\PaperChanger");

	switch(processor)
	{
	case	2:

		CopyFile("PaperChanger64.exe",
				"C:\\Program Files\\Shredded\\PaperChanger\\PaperChanger.exe",false);

		break;

	case	1:

		CopyFile("PaperChanger32.exe",
				"C:\\Program Files\\Shredded\\PaperChanger\\PaperChanger.exe",false);


		break;

	}

	CopyFile("book.ico","C:\\Program Files\\Shredded\\PaperChanger\\book.ico",false);

	WCHAR*	user = new WCHAR[256];
	int		pos = 0;
	
	IShellLink*		pLink;
	IPersistFile*	pFile;

	

	GetEnvironmentVariableW(L"USERPROFILE",user,256); 

	pos = wcslen(user);

	CoInitialize(0);

	CoCreateInstance(CLSID_ShellLink,NULL,CLSCTX_INPROC_SERVER,
					IID_IShellLink,(void**)&pLink);

	pLink->QueryInterface(IID_IPersistFile,(void**) &pFile);

	pLink->SetPath((LPCSTR) "C:\\Program Files\\Shredded\\PaperChanger\\PaperChanger.exe");

	pLink->SetDescription((LPCSTR)"Paper Changer");
	pLink->SetIconLocation((LPCSTR) "C:\\Program Files\\Shredded\\PaperChanger\\book.ico",0);


	switch(osVersion)
	{
	case	6:

		memcpy(&user[pos],
			L"\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\PaperChanger.lnk",
			160);
 
		break;

	case	5:

		memcpy(&user[pos],
			L"\\Start Menu\\Programs\\Startup\\PaperChanger.lnk",110);

		break;

	default:

		MessageBox(0,"Unsuported version","Installer Error",0);
		break;
	}

	pFile->Save(user,true);

	pFile->Release();
	pLink->Release(); 

	ShellExecuteW(hwnd,L"open",L"C:\\Program Files\\Shredded\\PaperChanger\\PaperChanger.exe",
			L"start",NULL,SW_SHOW);

	CoUninitialize();

	EnableWindow(but1,false);
}
Use the registry [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run].
Topic archived. No new replies allowed.