Writing into the Windows registry

User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Writing into the Windows registry

Post by driessen »

Hello,

Can someone provide me a small example how to update a key in the Windows registry?

Thanks.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
Richard Chidiak
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France
Contact:

Re: Writing into the Windows registry

Post by Richard Chidiak »

Michel

this is an example, HTH

Code: Select all

  oReg := TReg32():Create( HKEY_CURRENT_USER, "Control Panel\Desktop\WindowMetrics" )  // scrollbars
   I := 0

   oReg:Get( "ScrollHeight", @I )
   IF I # 0
       oReg:Set( "ScrollHeight", DVAL )
       oReg:Set( "ScrollWidth", DVAL )
       oReg:Close()
   ENDIF
 
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Writing into the Windows registry

Post by driessen »

Richard,

Thanks a lot for your help. But I'm afraid I don't quite understand.
I have never written into the registry before.

This is what I need to write into the registry :
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment]
"STCUNR"="53"
"STCURA"="Name1"
"STJUDA"="Name2"
Maybe you could translate it for my in FHW?

Thanks a lot in advance.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
AntoninoP
Posts: 347
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy
Contact:

Re: Writing into the Windows registry

Post by AntoninoP »

Code: Select all

oReg := TReg32():Create( HKEY_LOCAL_MACHINE, "ControlSet001\Control\Session Manager\Environment" ) 
oReg:Set( "STCUNR", "53")
oReg:Set( "STCURA", "name1" )
oReg:Set( "STJUDA", "name2" )
oReg:Close() 
and

Code: Select all

#define  HKEY_LOCAL_MACHINE      2147483650        // 0x80000002
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Writing into the Windows registry

Post by driessen »

Hello,

Thank you all for your help. Until now, everything is running just fine.

I use this function to change environment variables. Because I think it is better to change user environment varaibles, I changed my code to HKEY_CURRENT USER like this :

Code: Select all

#DEFINE HKEY_CURRENT_USER 2147483649 // 0x80000002

......

IF RegRet
   oReg := TReg32():Create( HKEY_CURRENT_USER,"Environment")
   IF UPPER(cPar) = "J"
      IF !EMPTY(cNAAM) ; oReg:Set("STJUDA",cNAAM) ; ENDIF
   ELSE
      IF !EMPTY(cNAAM) ; oReg:Set("STCURA",cNAAM) ; ENDIF
      IF !EMPTY(cNR  ) ; oReg:Set("STCUNR",cNR  ) ; ENDIF
   ENDIF
   oReg:Close()
ENDIF
By using this code, the variables are changed in the register.

Still one problem left : how do I activate them without having to reboot or to logoff?

Thanks.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Writing into the Windows registry

Post by Antonio Linares »

Michel,

You may need to use function SetEnvironmentVariable() from Windows API:

https://msdn.microsoft.com/en-us/librar ... s.85).aspx

Here you can review a thread about it:

http://forums.fivetechsupport.com/viewt ... 610#p73610
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Writing into the Windows registry

Post by driessen »

Antonio,

I tried that API-function. The variables are only changed while my application is running. But not permanently.

On the MSDN-page you send me, I also read : "Sets the contents of the specified environment variable for the current process.".

But thanks anyway.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Writing into the Windows registry

Post by driessen »

Could someone send me a small example how I can read my variables from the registry?

Thanks.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Writing into the Windows registry

Post by Antonio Linares »

Michel,

oReg := TReg32():New( HKEY_CURRENT_USER,"Environment")

MsgInfo( oReg:Get("STJUDA") )

oReg:Close()
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Writing into the Windows registry

Post by Antonio Linares »

Also you may use to set and retrieve environment variables:

hb_SetEnv( "michel", "this is a test" )

MsgInfo( GetEnv( "michel" ) )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Writing into the Windows registry

Post by driessen »

Sorry, Antonio.

Sure that I know that function but I completely forgot.

Thanks.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: Writing into the Windows registry

Post by Otto »

Michel,
please see my post:
http://forums.fivetechsupport.com/viewt ... ll#p143009
lg
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Writing into the Windows registry

Post by driessen »

Antonio,

I tried HB_SETENV but I got an error "unresolved function".

Which library do I need to add?

Thanks.

Otto,

I'll have a look at your topic. Thanks.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
MarcoBoschi
Posts: 925
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy
Contact:

Re: Writing into the Windows registry

Post by MarcoBoschi »

I use this function to Use pdfCreator in AutoSave Mode
It works
Bye

Code: Select all

FUNCTION SETTAREG( cDir , cFile , cAutoSave )
   LOCAL oReg

   oReg:=TReg32():New( HKEY_CURRENT_USER , "SOFTWARE\PDFCreator\Program" )
   oReg:Set( "UseAutosave"          , cAutoSave      )
   oReg:Set( "UseAutosaveDirectory" , cAutoSave      )
   oReg:Set( "AutosaveDirectory"    , UPPER( cDir )  )
   oReg:Set( "AutosaveFilename"     , UPPER( cFile ) )

   oReg:Close()

RETURN .T.
 
Marco Boschi
info@marcoboschi.it
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Writing into the Windows registry

Post by Antonio Linares »

Michel,

I am afraid that hb_SetEnv() is only available for Harbour
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply