Set Environment setting

I call the following function in my application, but it does not seem to 
take effect in the program until I exit and execute the program again. The 
change however is done when viewing it in Windows environment variables. But 
not instantly in the program. How do I fix this?

procedure SetUserEnvironmentVariable(const name, value: string);
var
  rv: DWORD;
begin
  with TRegistry.Create do
  try
    RootKey := HKEY_CURRENT_USER;
    OpenKey('Environment', False);
    WriteString(name, value);
    SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, LParam
      (PChar('Environment')), SMTO_ABORTIFHUNG, 5000, rv);
  finally
    Free
  end
end;
0
Andy
10/13/2011 4:48:50 AM
embarcadero.delphi.win32 2183 articles. 0 followers. Follow

2 Replies
1194 Views

Similar Articles

[PageSpeed] 59

"Andy Colmes" <andycolmes@yahoo.com> wrote in message 
news:410582@forums.embarcadero.com...

> I call the following function in my application, but it does not
> seem to take effect in the program until I exit and execute the
> program again. The change however is done when viewing it
> in Windows environment variables. But not instantly in the
> program.

Environment variables are loaded when the process is first created.  They 
are not tied to the WM_SETTINGCHANGE message.

> How do I fix this?

Call the Win32 API SetEnvironmentVariable() function to update the calling 
process, eg:

{code:delphi}
procedure SetUserEnvironmentVariable(const name, value: string);
var
  rv: DWORD;
begin
  with TRegistry.Create do
  try
    RootKey := HKEY_CURRENT_USER;
    if not OpenKey('Environment', False) then Exit;
    WriteString(name, value);
  finally
    Free;
  end;
  SetEnvironmentVariable(PChar(name), PChar(value));
  SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 
LParam(PChar('Environment')), SMTO_ABORTIFHUNG, 5000, rv);
end;
{code}

-- 
Remy Lebeau (TeamB)
0
Remy
10/13/2011 5:28:06 PM
Thanks very much Remy. That helped.

Cheers

Andy

"Remy Lebeau (TeamB)"  wrote in message 
news:410756@forums.embarcadero.com...

"Andy Colmes" <andycolmes@yahoo.com> wrote in message
news:410582@forums.embarcadero.com...

> I call the following function in my application, but it does not
> seem to take effect in the program until I exit and execute the
> program again. The change however is done when viewing it
> in Windows environment variables. But not instantly in the
> program.

Environment variables are loaded when the process is first created.  They
are not tied to the WM_SETTINGCHANGE message.

> How do I fix this?

Call the Win32 API SetEnvironmentVariable() function to update the calling
process, eg:

{code:delphi}
procedure SetUserEnvironmentVariable(const name, value: string);
var
  rv: DWORD;
begin
  with TRegistry.Create do
  try
    RootKey := HKEY_CURRENT_USER;
    if not OpenKey('Environment', False) then Exit;
    WriteString(name, value);
  finally
    Free;
  end;
  SetEnvironmentVariable(PChar(name), PChar(value));
  SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
LParam(PChar('Environment')), SMTO_ABORTIFHUNG, 5000, rv);
end;
{code}

-- 
Remy Lebeau (TeamB)
0
Andy
10/13/2011 5:57:20 PM
Reply:

Similar Artilces:

save settings // import settings // export settings
Name: miguel mayol Email: mitcoes_at_gmail.com Product: Firefox Summary: save settings // import settings // export settings Comments: I've just have a stack overflow problem in one of the computers of my office with internet explorer. The other ones, does work with our provider web site ok. But Firefox and Opera does work OK ata all the computers with this site, with problems of bad reading of contents at some pages (I supose becouse of MS HTML non compatible isues). If IE would have export // import settings, probably I've solved all the problems, but I would...

setting a character set
HiIn a security book i'm reading it says i should always set a character set for a web pagee.g. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />How do i do this?Is this characeter set achieved by the following in the web.config or do i need to do something else <globalization requestEncoding="utf-8" responseEncoding="utf-8" />Thanks a lotandrea...

Settings.Settings file
Settings.Design.cs file defaultInstance returns the localhost url instead of remote machine url. The webservice is hosted in remote machine so that the defaultinstance should be returns remote machine url but instead of it returns localhost url. The solution caches the settings somewhere in the physical path? Please anyone know the solution let me know. Thanks. The Settings.designer.cs file is the automatically-generated settings that you edit in the Settings.settings file. You should edit the value using the settings editor, not in the .cs file. To do that, double-click on the settings.s...

Set International Settings
I can't modify the International Settings, 'sthousand' and 'sdecimal', on windows 95. I have use 2 methods to do it, and with no results. I put this code in the event OPEN of the application : RegistrySet("HKEY_CURRENT_USER\Control panel\International","sDecimal", ",") RegistrySet("HKEY_CURRENT_USER\Control panel\International","sThousand", ".") ...and SetProfileString("c:\windows\WIN.INI", "intl", "sThousand",'"."') SetProfilestring("c:\windows\...

YOU RE-SET MY SETTINGS!!
Name: Product: Firefox Summary: YOU RE-SET MY SETTINGS!! Comments: I AM VERY, VERY UNHAPPY THAT YOUR UM-ANNOUNCED DOWNLOAD TO MY COMPUTER DHANGES MY FIREFOX SETTINGS!!!!! ENOUGH SO... THAT IF / WHEN IF HAPPENS AGAIN? I WILL PERMANENTLY SWITCH TO ANOTHER BROWSER!! WHAT IS PARTICULARLY GALLING IS HAT I HAVE CONVINCED DOZENS OF FRIENDS TO FIREFOX! STOP ^%$^*%$& WITH MY FIREFOX SETTINGS!!!!!!!!!!!!!! Browser Details: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729) From URL: http://hendrix.mozilla.org/ Note to...

Re: Set::Object + Set::Scalar
-----BEGIN PGP SIGNED MESSAGE----- Moin, >Sam Vilain wrote: >> So unless anyone has any great thoughts on the matter I'll cut out >> support for allowing the absence of items in the new `insert almost >> anything' Set::Object. It should be simpler in the long run, I hope. > >Just to follow up, the new version without the complicated parts of the >Set::Scalar API is now up on CPAN as Set::Object 1.08_02 and ready for >people to test it. Documented this time, too. > >Tels? :) Please Cc: me, I am not subscribed to p5p :-) Also...

Setting environment properties in Jaguar deletes class path setting of component
When I changed a custom environment property for a component from Jaguar component properties it wiped out all of my java classpath property setting in the component's property file except for the component's own target jar. This was my classpath setting before: com.sybase.jaguar.component.java.classes=ListObjectAll.jar,univs.ejb.*,com.s ybase.ejb.*,javax.naming.*,javax.naming.spi.*,powersoft.powerj.jaguar.*,com. sun.naming.internal.* This was my classpath property after making a change to the value of an environment property in the "Environment" tab in "Comp...

ConnectionString stored as plain-text in Settings.settings and Settings.Designer.cs
If you create a solution with a DAL much like the example in Working with Data in ASP.NET 2.0 (http://www.asp.net/learn/dataaccess/default.aspx?tabid=63) but you create your DAL as a seperate class library project from your website... the DAL project has a directory called Properties with a file called Settings.settings. Your connections string is stored as plain-text in this file (and it's sub-file) Settings.Designer.cs.Is there a way to encrypt this connection string much like you can if it were in a web.config. Hi This post http://forums.asp.net/thread/255840.aspx explains how to ...

superreview requested: [Bug 229371] deCOMtaminate nsIPresContext : [Attachment 140351] patch for LoadImage, StopImagesFor, Set/GetContainer, Set/GetLinkHandler, Set/GetVisibleArea, Set/GetPageDim, Ge
Brian Ryner <bryner@brianryner.com> has asked David Baron <dbaron@dbaron.org> for superreview: Bug 229371: deCOMtaminate nsIPresContext http://bugzilla.mozilla.org/show_bug.cgi?id=229371 Attachment 140351: patch for LoadImage, StopImagesFor, Set/GetContainer, Set/GetLinkHandler, Set/GetVisibleArea, Set/GetPageDim, GetLanguage http://bugzilla.mozilla.org/attachment.cgi?id=140351&action=edit ...

Setting up TB Account Settings
Years ago Lee told me how to use Account Settings to change the location for mail folders; it made it easier come backup time. Can someone please tell me how? I tried, but failed, by inserting the path name in Account Settings/Local Folders/Local Directory := C:\ATBird but it didn't work. Please help. (more to come ;-) ) Thanks Don The date and time was 2/21/2008 8:23 AM, and on a whim, Don Nickell pounded out on the keyboard: > Years ago Lee told me how to use Account Settings to change the location > for mail folders; it made it easier come backup time. Can so...

Set::Object + Set::Scalar
Hi all, I've just uploaded Set::Object 1.08_01 to CPAN. This has support for scalars as well as objects, and passes much of the Set::Scalar test suite. Set::Scalar includes the concept of a "universe", presumably so that operations like a set complement make sense. After implementing a lot of this functionality, and scratching my head several times until I saw how it needs to work to meet various Set tautologies (ValMorganizations like -($x * $y) == ( -$x + -$y ) ), I don't think it fits with Set::Object's approach to implement this kind of Set::Scalar fu...

Unable to set up Seamonkey settings
Name: Dixie Email: yankeedixieatcomcastdotnet Product: SeaMonkey Summary: Unable to set up Seamonkey settings Comments: I am not able to set up the sea monkey settings because all I get when I open it is the mozilla page and no way to open it!!!!!!!!!!\ This is so stupid and frustrating!!! I had to reinstall the OS and then had to reinstall Seamonkey BUT because of that mozilla page I am not able to get email and you force me to use that awful IE which I hate!! What is the matter with you that you won't let me open with something other than that mozilla page which is of ...

Account Settings
I am using TB 1.5 with XP Home, Pent III 733 and 512MB RAM. Using options "Account Setting Thunderbird, in particular the "Copies & Folders Options" for Sent, Draft and Templates Folders, despite selecting appropriate responses the "responses" do not stick. Consequently when I send a mail there is no record of the sent mail. I have considered commencing from scratch with a new profile. If I do this is it possible to transfer ALL of my existing mail folders with their contents to the new profile without loss of any the mail items? Many Thanks ...

Timeout setting set too short..
I'm having problems with some of my email accounts timing-out before they can login over my slow dialup connection. What setting do I change to make it wait longer for a response from the mail server? On 4/3/2009 2:28 AM, idigweeds wrote: > I'm having problems with some of my email accounts timing-out before > they can login over my slow dialup connection. What setting do I change > to make it wait longer for a response from the mail server? mailnews.tcptimeout http://kb.mozillazine.org/Modify_Thunderbird_settings ...

Web resources about - Set Environment setting - embarcadero.delphi.win32

Environment - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Strathmore Station land clearing under investigation for breaches of law, damage to environment
One of the country's largest single land clearings is investigated over concerns bulldozing may have broken the law.

Polar bear injured by radio collar part of U of A study, Environment Canada says
... from the University of Alberta are responsible for fitting a polar bear with a radio collar that appears to have injured the animal, an Environment ...

The Logic Pros: Making MIDI FX in Logic’s complex Environment simple
In this week’s episode of The Logic Pros , we will be taking a user-friendly look at Logic’s mysterious and powerful MIDI Environment. Along ...

Muslims face 'worsening environment of hate' in UK
... of violent assault have become a 'normal experience'. London, United Kingdom - British government policies are fuelling a worsening "environment ...

Creating the DevOps environment that'll give you an edge over the competition
... develop projects in shorter timeframes. With this in mind, what do these businesses need to consider to ensure they’ve got a DevOps environment ...

Yamaha introduces police bike designed for urban environments
... Tracer Police is making its debut this week at Milipol in Paris. The Tracer was developed for police patrols and rapid response in urban environments. ...

When Their Careers Are On The Line, Conservatives Vote With Progressives On The Environment
... in jeopardy. The Florida Senate race, for example, has Partrick Murphy suddenly calling himself a "champion of the middle class" and an "environmentalist," ...

Planned Parenthood: ‘Extremists Creating a Poisonous Environment That Feeds Domestic Terrorism in This ...
Planned Parenthood of the Rocky Mountain (PPRM) said about the recent shooting, “extremists are creating a poisonous environment..."

How pot affects the environment
As marijuana legalization heats up across the country, here's why the environment must be included in the debate, says Jennifer Carah.

Resources last updated: 11/28/2015 8:55:35 PM