GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 16-Jul-2004, 15:43
w332 w332 is offline
New Member
 
Join Date: Jul 2004
Posts: 4
w332 is on a distinguished road

newbie problem with RegSetValueEx


hello, im trying to alter this piece of code so i can add it to my program,
the code works, the "aplication" is added to the registry and boot, but
the problem is that the path in the reg. entry goes to the curent directory
of where the exe is in. i understand that this is cuz of the char *szBuf;
but even though i have searched google for a long time i dont understand
how i can change this, what i want to do is just add a path to my program
ex: c:\program files\my program (excuse me for not using // coments, since i dont understand the whole code im not cabable of doing this)
help very much apreciated..
CPP / C++ / C Code:
HKEY hkey;
char *szBuf;
TCHAR buff[255];
DWORD bufflLen = 255;
LPTSTR dirBuff = buff;

GetCurrentDirectory(buffLen, dirBuff);

buffLen = strlen(dirBuff);

if(buffLen > 3)
      szBuf = strcat(dirBuff, "\\myprogram.exe");
else
      szBuf = strcat(dirBuff, "myprogram.exe");

RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\Currentversion\\Run", 0, KEY_SET_VALUE, &hkey);
RegSetValueEx (hkey, "myprogram", 0, REG_SZ (LPBYTE) szBuf, strlen(szBuf) + 1);
RegCloseKey(hkey);
Last edited by dsmith : 16-Jul-2004 at 15:49. Reason: Please use [c] & [/c] for syntax highlighting
  #2  
Old 16-Jul-2004, 15:55
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
No guarantees, because I don't like messing with the registry, but why not try something like:
CPP / C++ / C Code:
HKEY hkey;
char *szBuf;
TCHAR buff[255];
DWORD bufflLen = 255;
LPTSTR dirBuff = buff;

//GetCurrentDirectory(buffLen, dirBuff); - Instead of this do:
strcpy(dirBuff,"c:\\program files");  //Or whatever directory you wanted.

buffLen = strlen(dirBuff);

if(buffLen > 3)
      szBuf = strcat(dirBuff, "\\myprogram.exe");
else
      szBuf = strcat(dirBuff, "myprogram.exe");

RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\Currentversion\\Run", 0, KEY_SET_VALUE, &hkey);
RegSetValueEx (hkey, "myprogram", 0, REG_SZ (LPBYTE) szBuf, strlen(szBuf) + 1);
RegCloseKey(hkey);

Like I said, don't hold me responsible for any of your pets dying from running the above code.
  #3  
Old 16-Jul-2004, 16:06
w332 w332 is offline
New Member
 
Join Date: Jul 2004
Posts: 4
w332 is on a distinguished road
:-P thanx a lot it worked .. !
gues the pets will be getting trough the day afterall
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie with pointer problems. moltarim C Programming Language 1 14-May-2004 10:46
Another FX 5600 problem (but with details that might shed light on this) BobDaDuck Computer Hardware Forum 2 16-Apr-2004 08:53
Newbie Problem with cin trs2988 C++ Forum 4 08-Feb-2004 13:05
problem with php5 cgi installation fab13 Apache Web Server Forum 3 19-Nov-2003 10:11
Code problem (a newbie question) monkster87 C++ Forum 3 11-Aug-2003 13:46

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:10.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.