FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Writing into the Windows registry
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Writing into the Windows registry
Posted: Tue Jun 30, 2015 02:26 PM

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. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 946
Joined: Thu Oct 06, 2005 07:05 PM
Re: Writing into the Windows registry
Posted: Tue Jun 30, 2015 02:40 PM
Michel

this is an example, HTH

Code (fw): Select all Collapse
  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
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: Writing into the Windows registry
Posted: Tue Jun 30, 2015 02:53 PM
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. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 375
Joined: Tue Feb 10, 2015 09:48 AM
Re: Writing into the Windows registry
Posted: Tue Jun 30, 2015 03:19 PM
Code (fw): Select all Collapse
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 (fw): Select all Collapse
#define  HKEY_LOCAL_MACHINE      2147483650        // 0x80000002
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: Writing into the Windows registry
Posted: Wed Jul 01, 2015 07:52 AM
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 (fw): Select all Collapse
#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. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Writing into the Windows registry
Posted: Wed Jul 01, 2015 08:02 AM
Michel,

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

https://msdn.microsoft.com/en-us/library/windows/desktop/ms686206(v=vs.85).aspx

Here you can review a thread about it:

http://forums.fivetechsupport.com/viewtopic.php?p=73610#p73610
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: Writing into the Windows registry
Posted: Wed Jul 01, 2015 08:25 AM
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. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: Writing into the Windows registry
Posted: Wed Jul 01, 2015 08:27 AM

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. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Writing into the Windows registry
Posted: Wed Jul 01, 2015 08:37 AM

Michel,

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

MsgInfo( oReg:Get("STJUDA") )

oReg:Close()

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Writing into the Windows registry
Posted: Wed Jul 01, 2015 08:38 AM

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
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: Writing into the Windows registry
Posted: Wed Jul 01, 2015 08:40 AM

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. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: Writing into the Windows registry
Posted: Wed Jul 01, 2015 10:13 AM

Michel,
please see my post:

viewtopic.php?f=3t=25706p=143009hilit=powershell#p143009
lg
Otto

&&&

Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: Writing into the Windows registry
Posted: Wed Jul 01, 2015 11:32 AM

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. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: Writing into the Windows registry
Posted: Wed Jul 01, 2015 11:36 AM
I use this function to Use pdfCreator in AutoSave Mode
It works
Bye

Code (fw): Select all Collapse
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
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Writing into the Windows registry
Posted: Wed Jul 01, 2015 08:08 PM

Michel,

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

regards, saludos

Antonio Linares
www.fivetechsoft.com