Video Screencast Help

system wide environment variable

Created: 24 Jan 2013 • Updated: 25 Jan 2013 | 9 comments
This issue has been solved. See solution.

i'm trying to apply a system wide environment variable in my package in Wise. The variable should be called "AT230NG" with its value set to BLUF<5 digit Location number><Device type>. Now, i already created a script for it that checks for the store number and device type (see below):

if DEVICETYPE Equals "XXY" then

     Set Variable DN-LOCATION to mid$(COMPNAME,5,4)

     Set Variable DN- DEVICE to mid$(COMPNAME,15,1)



Is there anything else i need to do to apply the string now captured in the variable DN-NAME to the AT230NG?

Thanks in advance..

Discussion Filed Under:

Comments 9 CommentsJump to latest comment

EdT's picture

I am not entirely sure what you are asking. There is an option within Installation Expert to set environment variables, and I believe it is self explanatory.

Just specify your property name as the value of the environment variable. Make sure your script runs early on in the InstallExecute sequence as an immediate custom action so that the property value is set before system changes are made.

If your issue has been solved, please use the "Mark as Solution" link on the most relevant thread.

ithomas1331's picture

Thanks EdT, i tried that and it still didn't work. I've decided to call the place the variable into the registry as opposed to having it in the installation expert. I'll let you know if it goes through as intended.

EdT's picture

Did you specify the public property with square brackets around the name?

Remember that you will need to restart the machine if you add or update an environment variable via the registry. Alternatively you need to send a message to all processes to reload the environment using a DLL call.

If your issue has been solved, please use the "Mark as Solution" link on the most relevant thread.

ithomas1331's picture

Point taken. On the side note though, how do it send the message to the rest of the processes to reload the environment variable with a DLL call? and which DLL should be called?


EdT's picture

This is a bit of Wisescript code I developed on a trial and error basis many years ago for NT4. There are absolutely NO warranties that it will work on any other version of windows.

To force the environment refresh under NT4 using Wisescript: 
item: Call DLL Function 
Function Name=SendMessageA 
Argument List=21-1 
Argument List=210 
Argument List=41Environment 
Return Variable=0 
I expect that some research with Google will throw up other solutions.
I would stress that I am not a programmer, so if you have access to any C++ gurus where you work, perhaps they could knock up a simple EXE you could call as a custom action.

If your issue has been solved, please use the "Mark as Solution" link on the most relevant thread.

JohanH's picture

I never got this to work in Wisescript. I think that you need to send L"Environment" (instead of Environment) as a unicode LPCWSTR, and this is not possible in Wise Script. There is only "string pointer", which means Ansi LPSTR or LPTSTR. I'm not sure, though.

ithomas1331's picture

In response to JohanH, to set the sytemwide environment variable what you do is call the variable that you are trying to pass as the environment variable in: "HKLM\SYSTEM\CurrentControlSet\Control\SessionManager\Environment" the value (AT230NG as seen from my example above) and pass the entry as %DN-NAME%

That should do the trick. If you're using wise sccript just use the Edit Registry command, and that should help you some. Lemme know if you have any problems with that.

JohanH's picture

Thanks, but I meant that I never got refreshing of the environment to work (so that the variable is immediately available for other windows). There is no problem setting the variable itself. But it requries at least restarting something before the variable is available for an already running application. Not a problem if the application checks the variable from the registry, of course.