Free Downloads, Community Forum,
FAQs and Developer Resources


Make /Tools Your Home | Link to us

Today's posts | Posts since last visit | Most Active Topics

All Forums Register Login Search Subscriptions My Profile Inbox
Tool Warehouse FAQs Resources Help Member List Address Book Logout

getreg and getreg_strvale

 
Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [SFU / Interix / SUA Technology] >> Interix Advanced Forum >> getreg and getreg_strvale Page: [1]
Login
Message << Older Topic   Newer Topic >>
getreg and getreg_strvale - Aug. 3, '06, 4:44:15 PM   
harvero

 

Posts: 14
Joined: Apr. 25, '06,
Status: offline
I currently have a program that uses hostid(). After much consideration I decided to try using the windows product ID or Digital prodcut ID as a replacement for hostid.

Does anyone have an example of using either of these two function (in SFU 3.5) to read the registry?


I’m trying to do the following which does not work. The getreg_strvalue returns a 1 indicating a failure.

#include <stdio.h>
#include <pwd.h>
#include <unistd.h>
#ifdef __INTERIX
#include "/usr/include/interix/interix.h"
#endif

main()
{

#ifdef __INTERIX
char *regkey="\\My Computer\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";

char *regstr = "ProductId";
char regdata[100] ;
size_t regsize = 100;
int rcode ;
#endif
#ifdef __INTERIX
rcode = getreg_strvalue( (PCWSTR) regkey, (PCWSTR) regstr, regdata, regsize);

hostid=(int) regdata;
printf("the key is %s\n",regkey);
printf("the str is %s\n",regstr);
printf("the int is %i\n",hostid);
printf("the string is %s<-\n",regdata);
printf("the rcode is %i \n",rcode);

#else
hostid=gethostid();
#endif


// some more code here has been removed

}

When I run the program I get:

adm.njcwvmsams2:/dev/fs/E/oracle/local/showpass.src>
adm.njcwvmsams2:/dev/fs/E/oracle/local/showpass.src>./a.out
the key is \My Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\Current
Version
the str is ProductId
the int is 8519400
the string is <-
the rcode is 1



From the interix.h file:

/*
* routines to get info from the registry
*/
/*
* getreg()
* OUT data - buffer to contain contents of registry entry
* OUT type - type of data returned in 'data'
* IN path - single byte string containing full registry pathname
* (Key and Value)
* INT size - max size of bytes of 'data' buffer
*/
extern int __cdecl getreg(char * /*path*/, int * /*type*/,
void * /*data*/, size_t * /*size*/);

/* getreg_strvalue()
* Return the ansi string from a registry entry.
* IN keystr - name of registry key (wide char string)
* IN valuestr - name of registry value (wide char string)
* OUT buf - buffer to store the result in (ansi string)
* IN bufsize - size of the buffer (in bytes)
*
* Return 0 on success, 1 on failure
*/
extern int __cdecl getreg_strvalue(PCWSTR /*keystr*/,
PCWSTR /*valuestr*/,
char * /*buf*/,
int /*bufsize*/);
Post #: 1
RE: getreg and getreg_strvale - Aug. 3, '06, 5:02:10 PM   
Rodney

 

Posts: 3714
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
> I’m trying to do the following which does not work. The getreg_strvalue returns a 1 indicating a failure.

Yup, you've specified the path incorrectly.
The path you've give is what the Win32 regedit utility mangles the registry paths
into to be "Windows User friendly". You need to use the real paths. Refer to the
MSDN/TechNet information for the actual path names. In this case you need to start
with "\Registry\Machine\" not "\My Computer\HKEY...\" (that's just pseudo mumbo jumbo).

(in reply to harvero)
Post #: 2
RE: getreg and getreg_strvale - Aug. 3, '06, 5:45:04 PM   
harvero

 

Posts: 14
Joined: Apr. 25, '06,
Status: offline
I've looked around and I wasn't able to find anything that explained the name mangling.

I've tried
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
and
\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion

instead of
\My Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion


with no luck.

Still looking for a code example of how to use the getreg functions.

Thanks

(in reply to Rodney)
Post #: 3
RE: getreg and getreg_strvale - Aug. 3, '06, 6:17:33 PM   
Rodney

 

Posts: 3714
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
I just told you what to use. I'll repeat:
>In this case you need to start
>with "\Registry\Machine\" not "\My Computer\HKEY...\" (that's just pseudo mumbo jumbo).

Thus:
\Registry\Machine\SOFTWARE\Microsoft\Windows NT\CurrentVersion

(in reply to harvero)
Post #: 4
RE: getreg and getreg_strvale - Aug. 4, '06, 2:38:26 PM   
markfunk

 

Posts: 670
Joined: Mar. 31, '03,
Status: offline
Check out INTERIX_SYSTEM_NAME or NT_VERSION_KEY or REGKEY_CurrentControlSet
in /usr/include/interix/registry.h for actual examples.

(in reply to Rodney)
Post #: 5
RE: getreg and getreg_strvale - Aug. 7, '06, 4:35:30 PM   
harvero

 

Posts: 14
Joined: Apr. 25, '06,
Status: offline
What does the L do in:

#define NT_VERSION_KEY \
L"\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion"

I've never seen a preprocessor define done like this.

(in reply to harvero)
Post #: 6
RE: getreg and getreg_strvale - Aug. 7, '06, 7:02:04 PM   
Rodney

 

Posts: 3714
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
It's for wide characters (wchar_t's).
This is the character representation used. You can convert multi-byte
characters (MB's) back-and-forth with it.

(in reply to harvero)
Post #: 7
RE: getreg and getreg_strvale - Aug. 8, '06, 4:17:19 PM   
harvero

 

Posts: 14
Joined: Apr. 25, '06,
Status: offline
So I've now changed my code to use the correct registry names:

main()
{

#ifdef __INTERIX
char *regkey= "\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion";

char *regstr = "ProductId";
char regdata[100] ;
int regsize = 100;
regdata[0]="";
int rcode ;
#endif

char pwd_seed[8] = "gasgWorZ";

// initialize the uid and make sure no arbitrary bit value.
char uid_str[8] = " ";
long hostid = 0;
int i,x,y,z, encrypted_bit;

// Get the user Id
struct passwd *pwentry;
pwentry=getpwuid(getuid());
strcpy(uid_str, pwentry->pw_name);

// Get hostid
#ifdef __INTERIX
rcode = getreg_strvalue( (PCWSTR) regkey, (PCWSTR) regstr, regdata, reg
size);
hostid=(int) regdata;
printf("the key is %s\n",regkey);
printf("the str is %s\n",regstr);
printf("the hostid int is %i\n",hostid);
printf("the product id string is %s<-\n",regdata);
printf("the rcode is %i \n",rcode);

#else
hostid=gethostid();
#endif


---------

But still no luck.

When I run it, I get:

adm.njcwvmsams2:/usr/apps/oracle/local/showpass.src>./a.out
the key is \Registry\Machine\Software\Microsoft\Windows NT\CurrentVersion
the str is ProductId
the hostid int is 8519400
the product id string is <-
the rcode is 1

(in reply to harvero)
Post #: 8
RE: getreg and getreg_strvale - Aug. 8, '06, 4:47:46 PM   
Rodney

 

Posts: 3714
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
When you use getreg_strvalue() the first two args have to be passed
in as wchar_t's. That's where the "L" comes in when doing a static declaration.
Or if your going to fill it in on-the-fly then use sprintf() with the "%S"
instead of "%s".

Change the following lines from:
> char *regkey= "\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion";
> char *regstr = "ProductId";
> printf("the key is %s\n",regkey);
> printf("the str is %s\n",regstr);

to:
> #include <wchar.h>
> wchar_t *regkey= L"\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion";
> wchar_t *regstr = L"ProductId";
> printf("the key is %S\n",regkey);
> printf("the str is %S\n",regstr);

Most find it easier to just use getreg() to start to avoid ther wchar_t/Unicode confusion.

(in reply to harvero)
Post #: 9
RE: getreg and getreg_strvale - Aug. 9, '06, 3:38:28 PM   
harvero

 

Posts: 14
Joined: Apr. 25, '06,
Status: offline
I just wanted to say thank you. I've made the changes and I'm working again.

(in reply to Rodney)
Post #: 10
Page:   [1]
All Forums >> [SFU / Interix / SUA Technology] >> Interix Advanced Forum >> getreg and getreg_strvale Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Search All Forums -

Advanced search


SPONSORS



Forum Software © ASPPlayground.NET Advanced Edition 2.5 ANSI

0.141