ReactOS  0.4.15-dev-1197-g8081ba9
regqueryvalue.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <wchar.h>
5 #include <windows.h>
6 
7 int main( int argc, char **argv ) {
8  ULONG ResultSize;
9  PWCHAR WcharResult;
10  WCHAR ValueNameWC[100];
11  PCHAR CharResult;
12  HKEY RegKey;
13  int i;
14 
15  if( argc < 2 ) {
16  printf( "Usage: regqueryvalue [key] [value]\n" );
17  printf( "Returns an HKEY_LOCAL_MACHINE value from the given key.\n" );
18  return 1;
19  }
20 
21  if ( RegOpenKeyExA( HKEY_LOCAL_MACHINE, argv[1], 0, KEY_READ, &RegKey )
22  != 0 ) {
23  printf( "Could not open key %s\n", argv[1] );
24  return 2;
25  }
26 
27  for( i = 0; argv[2][i]; i++ ) ValueNameWC[i] = argv[2][i];
28  ValueNameWC[i] = 0;
29 
30  if(RegQueryValueExW( RegKey, ValueNameWC, NULL, NULL, NULL, &ResultSize )
31  != 0) {
32  printf( "The value %S does not exist.\n", ValueNameWC );
33  return 5;
34  }
35 
36  WcharResult = malloc( (ResultSize + 1) * sizeof(WCHAR) );
37 
38  if( !WcharResult ) {
39  printf( "Could not alloc %d wchars\n", (int)(ResultSize + 1) );
40  return 6;
41  }
42 
43  RegQueryValueExW( RegKey, ValueNameWC, NULL, NULL, (LPBYTE)WcharResult,
44  &ResultSize );
45 
46  printf( "wchar Value: %S\n", WcharResult );
47  fflush( stdout );
48 
49  RegQueryValueExA( RegKey, argv[2], NULL, NULL, NULL, &ResultSize );
50 
51  CharResult = malloc( ResultSize + 1 );
52 
53  if( !CharResult ) {
54  printf( "Could not alloc %d chars\n", (int)(ResultSize + 1) );
55  return 7;
56  }
57 
58  RegQueryValueExA( RegKey, argv[2], NULL, NULL, (PBYTE)CharResult, &ResultSize );
59 
60  printf( " char Value: %s\n", CharResult );
61  fflush( stdout );
62 
63  free( WcharResult );
64  free( CharResult );
65 
66  return 0;
67 }
signed char * PCHAR
Definition: retypes.h:7
LONG WINAPI RegQueryValueExA(_In_ HKEY hkeyorg, _In_ LPCSTR name, _In_ LPDWORD reserved, _Out_opt_ LPDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ LPDWORD count)
Definition: reg.c:4023
static int argc
Definition: ServiceArgs.c:12
#define KEY_READ
Definition: nt_native.h:1023
#define free
Definition: debug_ros.c:5
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3331
uint16_t * PWCHAR
Definition: typedefs.h:56
#define argv
Definition: mplay32.c:18
FILE * stdout
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned char * LPBYTE
Definition: typedefs.h:53
smooth NULL
Definition: ftsmooth.c:416
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__wchar_t WCHAR
Definition: xmlstorage.h:180
int main(int argc, char **argv)
Definition: regqueryvalue.c:7
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
unsigned int ULONG
Definition: retypes.h:1
#define malloc
Definition: debug_ros.c:4
BYTE * PBYTE
Definition: pedump.c:66
#define printf
Definition: config.h:203
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12