Writing into the Windows registry

Writing into the Windows registry

Postby driessen » Tue Jun 30, 2015 2: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. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1399
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Writing into the Windows registry

Postby Richard Chidiak » Tue Jun 30, 2015 2:40 pm

Michel

this is an example, HTH

Code: Select all  Expand view

  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
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Re: Writing into the Windows registry

Postby driessen » Tue Jun 30, 2015 2: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. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1399
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Writing into the Windows registry

Postby AntoninoP » Tue Jun 30, 2015 3:19 pm

Code: Select all  Expand view
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  Expand view
#define  HKEY_LOCAL_MACHINE      2147483650        // 0x80000002
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: Writing into the Windows registry

Postby driessen » Wed Jul 01, 2015 7: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: Select all  Expand view
#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. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1399
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Writing into the Windows registry

Postby Antonio Linares » Wed Jul 01, 2015 8: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
User avatar
Antonio Linares
Site Admin
 
Posts: 41476
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Writing into the Windows registry

Postby driessen » Wed Jul 01, 2015 8: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. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1399
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Writing into the Windows registry

Postby driessen » Wed Jul 01, 2015 8: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. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1399
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Writing into the Windows registry

Postby Antonio Linares » Wed Jul 01, 2015 8:37 am

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: 41476
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Writing into the Windows registry

Postby Antonio Linares » Wed Jul 01, 2015 8: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
User avatar
Antonio Linares
Site Admin
 
Posts: 41476
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Writing into the Windows registry

Postby driessen » Wed Jul 01, 2015 8: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. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1399
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Writing into the Windows registry

Postby Otto » Wed Jul 01, 2015 10:13 am

********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6147
Joined: Fri Oct 07, 2005 7:07 pm

Re: Writing into the Windows registry

Postby driessen » 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. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1399
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Writing into the Windows registry

Postby MarcoBoschi » Wed Jul 01, 2015 11:36 am

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

Code: Select all  Expand view

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.
 
User avatar
MarcoBoschi
 
Posts: 1028
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Writing into the Windows registry

Postby Antonio Linares » Wed Jul 01, 2015 8:08 pm

Michel,

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

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

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 150 guests