3 Replies - 659 Views - Last Post: 19 May 2013 - 04:42 PM Rate Topic: -----

#1 theshowtekfan  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 27-September 11

Trying to add my new program to startup using regedit, please help

Posted 19 May 2013 - 03:38 PM

hi guys, im trying to get my program to start when the computer starts :P/> and right now i am trying to use registry for that and i have seen this method being used all over the internet but for some reason it ain't working for me right now ://> so i was hoping that anyone could please tell me what is wrong with my code ^^/>

see any thing that could cause an error ? :P/>

LPWSTR path = L"C:\\ProgramData\\IExplorer.exe";

		HKEY newValue;
    
		RegOpenKey(HKEY_LOCAL_MACHINE,TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Run"),&newValue);

		RegSetValueEx(newValue, path, 0, REG_SZ, (LPBYTE)path, sizeof(path));

		RegCloseKey(newValue);


Is This A Good Question/Topic? 0
  • +

Replies To: Trying to add my new program to startup using regedit, please help

#2 andrewsw  Icon User is offline

  • the case is sol-ved
  • member icon

Reputation: 6374
  • View blog
  • Posts: 25,755
  • Joined: 12-December 12

Re: Trying to add my new program to startup using regedit, please help

Posted 19 May 2013 - 03:54 PM

Do you mean "IExplorer" or "iexplore"? Is this located in c:\ProgramData (it isn't for me)? This is a protected system folder as well, which may be an issue.

This post has been edited by andrewsw: 19 May 2013 - 03:55 PM

Was This Post Helpful? 1
  • +
  • -

#3 andrewsw  Icon User is offline

  • the case is sol-ved
  • member icon

Reputation: 6374
  • View blog
  • Posts: 25,755
  • Joined: 12-December 12

Re: Trying to add my new program to startup using regedit, please help

Posted 19 May 2013 - 04:23 PM

RegOpenKey is also deprecated in favour of RegOpenKeyEx.

Looking at existing keys, I suspect you also need to embed extra quotes in your value:

""C:\\ProgramData\\IExplorer.exe""

// or

"\"C:\\ProgramData\\IExplorer.exe\""

(I haven't checked the correct syntax for C++)
Was This Post Helpful? 1
  • +
  • -

#4 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 5885
  • View blog
  • Posts: 20,092
  • Joined: 05-May 12

Re: Trying to add my new program to startup using regedit, please help

Posted 19 May 2013 - 04:42 PM

There are a few reasons why this could be failing for you:
1. If you are running on Windows Vista or later, you need to be running as administrator or have elevated privileges to be able to write into the HKEY_LOCAL_MACHINE key. Since you don't check your return values, or the returned registry key handle, you (and we) can't tell if that's the reason.

2. If you are compiling for for ANSI, then your call to RegSetValueEx() maybe putting the incorrect values into the registry since you are passing a UNICODE string for a REG_SZ type. Again, you don't check the return value to see if that write succeeded.

3. Your anti-virus software maybe "protecting" the HKEY_LOCAL_MACHINE hive and intercepting and throwing away your attempts to write into the hive.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1