I want my program to run on start up through editing the registry, how would i do that? Certain API's? or a specific way through c++ to do it? Or is that even the right method? Basically i would prefer to not use the startup folder in XP.

Dani AI

Generated

Quick summary: adding a string value to the Windows "Run" registry key is the usual way to auto-start an app (per-user vs. machine-wide). pointed you in the right direction — use the Win32 registry APIs rather than trying to drop a file in the Startup folder if you want a programmatic solution.

Two practical clarifications tied to the thread: the first parameter to RegCreateKeyEx is an HKEY constant (for example the per-user root), not a textual path — that is why advised changing your string to an HKEY. The typical flow is: create/open the Run key, write a REG_SZ value whose data is the full executable path (and args), check the API return codes for ERROR_SUCCESS, then close the handle. On modern compilers remember to include the right headers and link advapi32.lib.

Troubleshooting notes that often fix compile/run problems: do not pass std::string where an LPCTSTR/LPCWSTR is expected (use TEXT()/wide strings or the A/W function variants); pay attention to Unicode vs ANSI signatures; HKLM writes require elevation (UAC) while HKCU does not; 32-bit apps on 64-bit Windows can hit WOW64 redirection (use the KEYWOW64* access flags if you need a specific registry view). Always use absolute paths and include the terminating null when giving the byte count for a string value.

For robustness and user-friendliness, consider using an installer or the Task Scheduler instead of raw Run entries. Official API references: RegCreateKeyEx documentation and RegSetValueEx documentation.

Recommended Answers

All 9 Replies

You call this a C++ question?

Well ya... i asked how you would do something like this because I don't know how and I'm writing code in c++ right now... and your kind've being a dick, even in my other thread you insulted me.

Well ya... i asked how you would do something like this because I don't know how and I'm writing code in c++ right now... and your kind've being a dick, even in my other thread you insulted me.

I didn't insult you in the thread, but if you're going to cry like a babby about insults that you've imagined, I think you deserve one now.

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run

what do u think?...

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run

what do u think?...

ya, i got that much, but what would i do with that?

RegCreateKey...RegSetValue...RegCloseKey...etc.

Thats what i was looking for lol. ill just look that up on msdn.

thanks

Sorry for double post, but im having trouble getting it to compile.

string vOut;
RegCreateKeyEx("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", "clutch", 0, NULL, 0x00000000L, 0xF003F, NULL, &vOut, NULL);

I was going off of MSDN and was slightly confused the entire time, so im wondering how do i fix this up? Thanks

LONG WINAPI RegCreateKeyEx(
   HKEY hKey,
   LPCTSTR lpSubKey,
   DWORD Reserved,
   LPTSTR lpClass,
   DWORD dwOptions,
   REGSAM samDesired,
   LPSECURITY_ATTRIBUTES lpSecurityAttributes,
   PHKEY phkResult,
   LPDWORD lpdwDisposition
);

string vOut; //....that's wrong

HKEY vOut;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.