registry read

HMG Samples and Enhancements

Moderator: Rathinagiri

Post Reply
User avatar
dragancesu
Posts: 920
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

registry read

Post by dragancesu »

I tried an example of a function and it works
When I tried to read the guid it shows NIL
This is a 10-64 bit version

Do you do this program to you?

It should return the windows uuid number, I wanted to use it to protect the program, it's a unique number for every windows installation


Code: Select all

/*
 * HMG - Harbour Win32 GUI library Demo
 *
 * Copyright 2002-2008 Roberto Lopez <mail.box.hmg@gmail.com>
 * http://www.hmgforum.com//
 * Based on HBW32 samples included in Harbour distribution

*/

#include "hmg.ch"

PROCEDURE Main()

	DEFINE WINDOW form_1 ; 
		AT 114,218 ;
		WIDTH 334 ;
		HEIGHT 276 ; 
		TITLE 'REGISTRY TEST' ; 
		MAIN 

		DEFINE MAIN MENU

			DEFINE POPUP "Test"
				MENUITEM 'Read Registry' ACTION ReadRegistryTest()
			END POPUP

		END MENU


	END WINDOW 

	form_1.center
	form_1.activate

Return NIL

Procedure ReadRegistryTest()

    private reg_key := ''
   
    reg_key := hb_ValToStr ( RegistryRead( 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\MachineGuid' ))

	MsgInfo ( reg_key, 'UUID' )

Return
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: registry read

Post by edk »

Hi Dragan.
Simply change the registry key from:

Code: Select all

reg_key := hb_ValToStr ( RegistryRead( 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\MachineGuid' ))
to:

Code: Select all

reg_key := hb_ValToStr ( RegistryRead( 'HKLM\SOFTWARE\Microsoft\Cryptography\MachineGuid' ))
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: registry read

Post by edk »

I apologize to Dragan, I did not read this:
dragancesu wrote: Fri Nov 24, 2017 1:39 pm (...)This is a 10-64 bit version(...)
Try this code, it works on my Win10 64bit:

Code: Select all

/*
 * HMG - Harbour Win32 GUI library Demo
 *
 * Copyright 2002-2008 Roberto Lopez <mail.box.hmg@gmail.com>
 * http://www.hmgforum.com//
 * Based on HBW32 samples included in Harbour distribution

*/
#include "hmg.ch"
#define KEY_WOW64_64KEY 0x0100

#define KEY_WOW64_32KEY 0x0200

PROCEDURE Main()

	DEFINE WINDOW form_1 ; 
		AT 114,218 ;
		WIDTH 334 ;
		HEIGHT 276 ; 
		TITLE 'REGISTRY TEST' ; 
		MAIN 

		DEFINE MAIN MENU

			DEFINE POPUP "Test"
				MENUITEM 'Read Registry' ACTION ReadRegistryTest()
			END POPUP

		END MENU


	END WINDOW 

	form_1.center
	form_1.activate

Return NIL

Procedure ReadRegistryTest()

    private reg_key := 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\MachineGuid'
    private reg_key_value:=''

    IF hb_osIs64bit()
	reg_key_value := hb_ValToStr (win_regRead ( reg_key,,KEY_WOW64_32KEY) )
	IF reg_key_value='NIL'
		reg_key_value := hb_ValToStr (win_regRead ( reg_key,,KEY_WOW64_64KEY) )
	ENDIF
    ELSE
	reg_key_value := hb_ValToStr ( win_regRead( reg_key ))
    ENDIF

    MsgInfo ( reg_key_value, 'UUID' )

Return
User avatar
dragancesu
Posts: 920
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: registry read

Post by dragancesu »

Thank you EDK
Post Reply