Old 25th November 2016, 14:01   #1
xbarns
Senior Member
 
xbarns's Avatar
 
Join Date: Aug 2007
Location: Frankfurt, Germany
Posts: 187
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
xbarns is offline   Reply With Quote
Old 25th November 2016, 15:04   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
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...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 25th November 2016, 15:14   #3
xbarns
Senior Member
 
xbarns's Avatar
 
Join Date: Aug 2007
Location: Frankfurt, Germany
Posts: 187
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...
xbarns is offline   Reply With Quote
Old 25th November 2016, 15:19   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
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.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 25th November 2016, 15:33   #5
xbarns
Senior Member
 
xbarns's Avatar
 
Join Date: Aug 2007
Location: Frankfurt, Germany
Posts: 187
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!
xbarns is offline   Reply With Quote
Old 26th November 2016, 12:05   #6
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 916
I've created a plugin that deals with environment variables, check it out here: http://nsis.sourceforge.net/EnVar_plug-in.

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump