Registry problem (creation of key )

HEy guys . I am currently doing a project in which i need to register a key in HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run
directory where the keys for the program that needs to run on startup are defined !


Hers my code it doesn't seem to be creating a key !
Any suggestion or aany alternative programs ?

Pls i need help soon , the project is due on monday !

thnx in advance !


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

#include <windows.h>
#include <iostream>

using namespace std;

int main()


{
		cout << "Hello World"; 
	

HKEY hKey;


	// The path of your exe file. If you have a long path, 
	// change the number of elements in the array.  
	unsigned char PathToFile[100]="C:\\Users\\dhayalan\\Desktop\\junk\\clco.exe";

	
	// The directory of registry to be opened.
	//RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",0,	KEY_SET_VALUE,&hKey );

	
	// Set the Value which iHKEY hKey ; 
    DWORD disp ; 
    DWORD createError = RegCreateKeyEx( 
        HKEY_LOCAL_MACHINE,   // handle of an open key 
        "Software\\Microsoft\\Windows\\CurrentVersion\\Run",   // subkey name 
        0,          // reserved 
        NULL,       // class string 
        REG_OPTION_NON_VOLATILE, // permanent entry 
        KEY_READ | KEY_WRITE,   // desired security access 
        NULL,       // security attributes (default) 
        &hKey,     // handle for opened key returned 
        &disp ) ;   // created new vs. opened existing 
    if ( createError == ERROR_SUCCESS ) 
    { 
        // now can use hKey in other APIs 
    } 
    else 
    { 
        // createError is an error code which can be looked up 
        // in WINERROR.H or fed into FormatMessage. 
    } 
//directory of your exe file. 
	RegSetValueEx(hKey, "hello world",0,REG_SZ,PathToFile,sizeof(PathToFile));

	
	//Close key.
	RegCloseKey(hKey);



   return 0;
}
Topic archived. No new replies allowed.