How To define operating system environment variable ?

How To define operating system environment variable ?

Postby vilian » Wed Jan 14, 2009 6:03 pm

Hi,

I need to define through the program, an operating system environment variable to be seen by all the applications. He is possible?

Already I obtained to define with the following program. But the program that created only obtains to see the variable. It would like that all the programs in saw it to execution.

Code: Select all  Expand view

SetEnvironmentVariable("VFAPORTAL","c:\teste ")

#pragma BEGINDUMP

#include <windows.h>

HB_FUNC( SETENVIRONMENTVARIABLE )
{
   hb_retl( SetEnvironmentVariableA( (LPCSTR) hb_parcx( 1 ),
                                     (LPCSTR) hb_parcx( 2 )
                                     ) ) ;
}

#pragma ENDDUMP

Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
vilian
 
Posts: 920
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: How To define operating system environment variable ?

Postby Antonio Linares » Thu Jan 15, 2009 1:16 am

Vilian,

SetEnvironmentVariable()
"This function has no effect on the system environment variables or the environment variables of other processes."
http://msdn.microsoft.com/en-us/library/ms686206(VS.85).aspx

But you can do it this way:
"Calling SetEnvironmentVariable has no effect on the system environment variables. To programmatically add or modify system environment variables, add them to the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment registry key, then broadcast a WM_SETTINGCHANGE message with lParam set to the string "Environment". This allows applications, such as the shell, to pick up your updates. Note that the values of the environment variables listed in this key are limited to 1024 characters."
http://msdn.microsoft.com/en-us/library/ms682653(VS.85).aspx
regards, saludos

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

Re: How To define operating system environment variable ?

Postby vilian » Thu Jan 15, 2009 1:21 pm

Antonio,

I created in the register of windows ( HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment ) the following entrance: VFAPORTAL.

Later I try to modify its content with the following program:

Code: Select all  Expand view
#define WM_SETTINGCHANGE     26

SendMessage(-1,WM_SETTINGCHANGE,"VFAPORTAL","TESTE3")
 


But nothing it happens, what I am making made a mistake?
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
vilian
 
Posts: 920
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: How To define operating system environment variable ?

Postby vilian » Sat Jan 17, 2009 1:01 pm

Up
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
vilian
 
Posts: 920
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: How To define operating system environment variable ?

Postby Antonio Linares » Sat Jan 17, 2009 4:10 pm

Vilian,

Try to use 0xFFFF instead of -1
regards, saludos

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

Re: How To define operating system environment variable ?

Postby Antonio Linares » Sat Jan 17, 2009 4:12 pm

Also use "Environment" instead of "TESTE3"
regards, saludos

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

Re: How To define operating system environment variable ?

Postby Antonio Linares » Sat Jan 17, 2009 4:23 pm

Vilian,

Finally, use 0 (zero) instead of "VFAPORTAL" when calling SendMessage()
regards, saludos

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

Re: How To define operating system environment variable ?

Postby vilian » Tue Jan 20, 2009 1:47 pm

Antonio,

I did not understand. The command would be thus then?

SendMessage(0xFFFF,WM_SETTINGCHANGE,0,"Environment")

But as I define that changeable it goes to be modified and which the new value?
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
vilian
 
Posts: 920
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: How To define operating system environment variable ?

Postby Antonio Linares » Tue Jan 20, 2009 6:31 pm

Vilian,

> SendMessage(0xFFFF,WM_SETTINGCHANGE,0,"Environment")

Yes, that is what I meant

> But as I define that changeable it goes to be modified and which the new value?

You set the new value in the registry, then notify all the windows about such change.

It should work that way
regards, saludos

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

Re: How To define operating system environment variable ?

Postby vilian » Tue Jan 20, 2009 8:01 pm

Antonio,

grateful for the help.

But as sending this value for the registry?
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
vilian
 
Posts: 920
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: How To define operating system environment variable ?

Postby Antonio Linares » Tue Jan 20, 2009 10:50 pm

Vilian,

Please review FWH\samples\testrg32.prg
regards, saludos

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

Re: How To define operating system environment variable ?

Postby vilian » Wed Jan 21, 2009 1:30 pm

Antonio,

I made thus:

Code: Select all  Expand view
#include "FiveWin.Ch"

#define  WM_SETTINGCHANGE        26
#define  HKEY_LOCAL_MACHINE      2147483650

function Main()

   LOCAL oReg, cName, uVar

   oReg := TReg32():New( HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Control\Session Manager\Environment",.t. )

   oReg:Set( "VFAPORTAL", "SIF212" )
   oReg:Close()

   SendMessage(0xFFFF,WM_SETTINGCHANGE,0,"Environment")
   SysRefresh()

   ? GetEnv("VFAPORTAL")

return nil


But the GetEnv continues returning the old value !
Seeing through the RegEdit I confirm the change in the value. but GetEnv continues returning me the old one. Why?
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
vilian
 
Posts: 920
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: How To define operating system environment variable ?

Postby Antonio Linares » Mon Jan 26, 2009 9:20 am

Vilian,

Have you tried to close and restart the application after such change ?
regards, saludos

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


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 8 guests