Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

How to set up an Environment Variable in the Registry


4 replies to this topic

scott matthews2

scott matthews2
  • Members
  • 13 posts

Posted 05 December 2001 - 15:30

How can I set up an Environment Variable in the Registry and then refer to this variable in another registry entry.

Example:  I have the following registry entry/command for opening up a ".frm" file after my installation completes:
"C:\Program files\ROC\Jre13\javaw.exe"

I would like to set up a registry/environment variable named "JavaPath" where "JavaPath" holds the entry of c:\program files\roc\jre13.  I can then change the above command to %JavaPath%\javaw.exe.

Can this be done and how would I do it?  If it matters, this will be for a Windows 98,NT, & 2000 systems and I have version IS6.22.

Thanks for your help


lasenbby

lasenbby
  • Members
  • 744 posts

Posted 05 December 2001 - 21:12

98 you will have to add it to the autoexec file and make them reboot.  Appending this line to me seems easiest to install and for uninstall:
JVar=....

And on uninstall you look for "JVar=" and remove the line.  

The others you can write to the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment key a value (JVar) with data (%JVar%\...) and then flush the registry and the variable should be available.  Search this forum for "flush" and "environment" and I bet you find good info.


scott matthews2

scott matthews2
  • Members
  • 13 posts

Posted 07 December 2001 - 15:45

I appreciate your response, but this did not work in Win NT or Windows 2000.  I did not try the Windows 98 solution.  Also, I did a search for "flush" and also "environment" as you suggested.  13 entries appeared and now of them had information on how to flush the registry or any useful environment information.  Basically, I rebooted after I made changes to the registry to get around the "Flush".

How do you "Flush" the registry?

Here is what occured when I try your suggested registry changes:
The sample/example I want to try is the following:
"C:\Program files\ROC\Jre13\javaw.exe"

Here what I got: (Again in both NT & 2000)
1. I set up %ROCJAVA% variable in the location HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment which holds the following:
  "C:\Program files\ROC\Jre13"
2. I get out of the registry and reboot
3. I go into the file extension open command and put in the    following:  %ROCJAVA%\java.exe
  A message box appears that says it cannot find the file.
  Note: I tried many combinations of this, putting in a    quote quote mark in the variable because of the long file    name.  I tried putting in the entire path with the    java.exe java.exe in the variable.  None of these worked.  

  Just for grins, I put in %ROCJAVA% otepad.exe even       though the notepad.exe is not in this subdirectory. It      likes this now and lets me out of the screen. Now I go      back into the open command and it has
  In NT:
  C:\Program files\ROC\Jre13 otepad.exe
  In 2000:
  %ROCJAVA% otepad.exe        

So it seems it is doing some type of variable substitution, but only after it is able to leave the open command

Summary:  I hope the above sheds some light.  As always I appreciate the input of anyone trying to help.

Scott Matthews


lasenbby

lasenbby
  • Members
  • 744 posts

Posted 07 December 2001 - 19:57

One thing to remember is that this does not work if you run it through from IDE debugging or run.  It will however if you run it from the setup.exe. (IS does not process the msg.)

To flush the registry (also there is a utility or a topic on this site that basically does the same thing.)
#define WM_SETTINGCHANGE  0x001A
#define HWND_BROADCAST    0xffff

function...
STRING    szEnv;
POINTER     pEnv;
...
begin
...
regdbsetdefaultroot...

// be sure to sure the expandable string option if it is one
reddbsetkeyvalueex....
...
// Flush the NT registry to all applications.
szEnv = "Environment";
pEnv = &szEnv ;
SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, pEnv);
...


It will not work on 9x because they do not handle env vars the same way.  You have to place code in the autoexec file.

(I wrote this before I realized that Stefan removed older posts so the flush may not have found the correct post.  Sorry for the wild goose chase...)



Stefan Krueger

Stefan Krueger

    InstallSite.org

  • Administrators
  • 13,269 posts

Posted 09 December 2001 - 20:35

Quote
Quote: from lasenbby on 7:57 pm on Dec. 7, 2001(I wrote this before I realized that Stefan removed older posts so the flush may not have found the correct post.  Sorry for the wild goose chase...)

In general I don't remove messages. But I just realized that some messages had "vanished" (probably due to a server problem). I'll try to restore them. If you see messages disappearing please alert me a webmaster@installsite.org. Sorry for the trouble.