Welcome Guest ( Log In | Click here to Register a free account now! )
Welcome to Bleeping Computer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.
May 11 2009, 03:46 AM
Post
#1
|
|
|
Member ![]() ![]() Group: Members Posts: 16 Joined: 11-May 09 Member No.: 330,588 |
Hello all, I got some problem with these functions: RegCreateKey, RegSetValueEx,RegQueryValueEx,RegOpenKeyEx and I dont need a URL to msdn. The problem is that its working 2/3 :-).
Output in the register should be like this: Name: Test Type: REG_SZ Data: C:\WINDOWS\system32\test.exe But I get this: Name: Test Type: REG_SZ Data: [][][][][][][][][][][][][][] My code is below, do anyone see the problem? hope you dont mind to help me :-). //KaZu #include <windows.h> #include <stdio.h> #include <winuser.h> #define BUFSIZE 120 int test_key(void); int create_key(char *); int main(void) { char *path = new char[40]; path ="C:\\WINDOWS\\system32\\test.exe"; int test,create; // just holders to get the return value from functions test=test_key(); /*check if key is available for opening*/ if (test==2)/*create key*/ { //*the path in which the file needs to be*/ create=create_key(path); } int test_key(void) // function to check if we could open the register and check the value for specified name { int check; HKEY hKey; char path[BUFSIZE]; DWORD buf_length=BUFSIZE; int reg_key; reg_key=RegOpenKeyEx(HKEY_LOCAL_MACHINE,TEX("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"),0,KEY_QUERY_VALUE,&hKey); // Open register if(reg_key!=ERROR_SUCCESS)// If the value isnt ERROR_SUCCESS it have failed and returns a error, set the check = 1 { check=1; return check; } reg_key=RegQueryValueEx(hKey,TEXT("test"),NULL,NULL,(LPBYTE)path,&buf_length); // Get value for"test" if((reg_key!=0)||(buf_length>BUFSIZE)) check=2; if(reg_key==0) check=0; RegCloseKey(hKey); // Just close the key return check; } int create_key(char *path) { int reg_key,check; HKEY hkey; reg_key=RegCreateKey(HKEY_LOCAL_MACHINE,TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"),&hkey); // Create a key if(reg_key==0) { RegSetValueEx((HKEY)hkey,TEXT("test"),0,REG_SZ,((LPBYTE)path),(sizeof(path))+1); // Set the value check=0; return check; } if(reg_key!=0) check=1; RegCloseKey(hkey); // close the key return check; } This post has been edited by KaZu: May 11 2009, 03:48 AM |
|
|
|
KaZu C++ register string value error May 11 2009, 03:46 AM
Billy O'Neal You're mixing ANSI and Unicode. Use wchar_t fo... May 11 2009, 12:30 PM
KaZu int create_key(wchar_t *);
wchar_t *path = new wc... May 11 2009, 01:06 PM
groovicus
How are we supposed to know? We're not the o... May 11 2009, 01:48 PM
KaZu Im sorry for the bad information, It was just a qu... May 11 2009, 01:52 PM
KaZu Here is the new code if it helps and you get any i... May 11 2009, 01:56 PM
Billy O'Neal Here is the new code if it helps and you get any i... May 11 2009, 02:23 PM
Billy O'Neal
This code is invalid and causes a memory leak.
N... May 11 2009, 02:24 PM
KaZu I fixed the L problem, the sizeof should take out ... May 11 2009, 03:03 PM
Billy O'Neal What is sizeof(path) ? Remember, arrays in C(++) a... May 11 2009, 03:12 PM
KaZu Thanks alot for the info and now my program is wor... May 11 2009, 03:23 PM
Billy O'Neal No problem :)
However... I have a question for yo... May 11 2009, 04:21 PM
KaZu Hehe I can see that it allocate memory and should ... May 11 2009, 04:40 PM
Billy O'Neal Yep :)
What did this line do?
path = L"C:... May 11 2009, 05:14 PM
KaZu The first, I mixed up Unicode and ANSI code, had t... May 12 2009, 01:20 AM
Billy O'Neal That's what needed fixed, but that's not t... May 12 2009, 02:53 PM
KaZu Ah yes :)
KaZu May 13 2009, 03:50 AM
Billy O'Neal Err... What?
Billy3 May 13 2009, 09:47 PM
KaZu Aha didnt see your question, just the first thing ... May 14 2009, 09:28 AM
Billy O'Neal Heehe... but you never allocated that string, did ... May 14 2009, 03:11 PM
KaZu hehe no :P
KaZu May 14 2009, 03:27 PM
Billy O'Neal What operation does the = actually perform here?
... May 14 2009, 03:29 PM
KaZu Hm I guess that = says that Path points on a new m... May 15 2009, 02:15 AM
KaZu One more question. Would this code work on vista?
... May 17 2009, 08:28 AM
Billy O'Neal Hello :)
Nope. When windows starts your EXE file... May 17 2009, 05:23 PM
KaZu Ah thanks for the information. I used c++ for this... May 18 2009, 03:31 AM
KaZu Billy can I ask you another question instead of cr... May 18 2009, 05:42 AM
KaZu Yes it´s :-) Would be great for others to have a a... May 20 2009, 09:48 AM![]() ![]() |
| Lo-Fi Version | Time is now: 24th November 2009 - 04:17 PM |