-
May 11th, 2009, 10:01 AM
#1
C++ register value error
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;
}
-
May 11th, 2009, 10:07 PM
#2
Re: C++ register value error
What does this C:\WINDOWS\system32\test.exe do and why do you want to run it every time with Windows?
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
May 14th, 2009, 09:09 AM
#3
Re: C++ register value error
Originally Posted by VladimirF
What does this C:\WINDOWS\system32\test.exe do and why do you want to run it every time with Windows?
I have already solved it. It´s a project for checking how register works in windows 32. Just PM me for info
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|