weird registry problem

Im trying to add my program to the windows run registry

my code seems to work an it sets the key in the registry
an the program location is fine.
the problem is that my program dont start up with windows.

but if i set the key myself in the registry an the same location to the program as my code does the program starts with windows.

does GetModuleFileName not work with writing to registry like im trying?

1
2
3
4
5
6
				HKEY Handle_Key = 0;
				char FileName[MAX_PATH];
				RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run",  0, KEY_ALL_ACCESS, &Handle_Key );
				GetModuleFileName(NULL,FileName,sizeof(FileName));				
				RegSetValueEx( Handle_Key, "MyProgram", 0, REG_SZ, (PBYTE)&FileName, sizeof(FileName) );
				RegCloseKey(Handle_Key);
Use this :

1
2
3
4
5
6
7
8
9
10
HKEY Handle_Key = 0;
    char FileName[MAX_PATH];
    RegOpenKeyExA( HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run",  0, KEY_ALL_ACCESS, &Handle_Key );
    GetModuleFileNameA(NULL,FileName,sizeof(FileName));


    
    RegSetValueExA( Handle_Key, "MyProgram", 0, REG_SZ, (PBYTE)&FileName, strlen(FileName) + 1);
    
    RegCloseKey(Handle_Key);
Topic archived. No new replies allowed.