Winamp & Shoutcast Forums

Winamp & Shoutcast Forums (http://forums.winamp.com/index.php)
-   NSIS Discussion (http://forums.winamp.com/forumdisplay.php?f=65)
-   -   x86/x64 Environment Variables Read/Write (http://forums.winamp.com/showthread.php?t=398973)

xbarns 25th November 2016 14:01

x86/x64 Environment Variables Read/Write
 
Hi all,

i need to modify an EnvironmentVariable in both the x86 and the x64 environment of a machine (Windows 2008/12/16).

I was playing around with the x64.nsh, but that didn't get me anywhere.

The variable to be modified is PSModulePath and i need to append a path to it, and depending on the environment this is later used in, it is either x86 (C:\Program Files (x86)\...) or x64 (C:\Program Files\....).

Any ideas?

Thanks for your help.
x

Anders 25th November 2016 15:04

Do you want to make a permanent change by writing to the registry or temporary for programs started by your installer?

It sounds to me like you are talking about the former and then you need to use SetRegView when dealing with the registry...

xbarns 25th November 2016 15:14

It supposed to be permanent, the problem with the registry is that the Variable "PSModulePath" in "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" does not reflect what is actually available in Powershell

Also (as far as i know) there is no different x86/x64 view in that part of the registry...

Anders 25th November 2016 15:19

https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx says
Quote:

When Windows PowerShell starts, PSModulePath is created as a system environment variable with the following default value: $home\Documents\WindowsPowerShell\Modules; $pshome\Modules
If the registry uses a reg expand string and %ProgramFiles% then the program should get the correct folder automatically.

xbarns 25th November 2016 15:33

I actually knew that page, seems like even with glasses thorough reading is not automatic :)

I guess i will go with

$CurrentValue = [Environment]::GetEnvironmentVariable("PSModulePath", "Machine")
[Environment]::SetEnvironmentVariable("PSModulePath", $CurrentValue + ";C:\Program Files\Fabrikam\Modules", "Machine")

This still needs to be done for both x86 and x64 but that is easy to handle from NSIS.

Thanks for your help!

JasonFriday13 26th November 2016 12:05

I've created a plugin that deals with environment variables, check it out here: http://nsis.sourceforge.net/EnVar_plug-in.


All times are GMT. The time now is 17:44.

Copyright © 1999 - 2010 Nullsoft. All Rights Reserved.