![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Changing the PATH variable in the registry with Powershell It would be really nice to be able to manipulate the Path variable. Adding to the end of $env:Path will change the Path variable for the session of shell in powershell. But then your changes go poof when you close the session. If you want to change the path permanently...you need to edit the registry. This is pretty easy to do. $original = (Get-ItemProperty "HKLM:SYSTEM\CurrentControlSet\Control\Session Manager\Environment" Path ).Path Set-ItemProperty "HKLM:SYSTEM\CurrentControlSet\Control\Session Manager\Environment" Path -value ( $original + ";" + $dirname ) The issue is that registry settings are only read at login. Starting a new powershell or cmd shell does not pick up the new settings until I reboot. When I google it seems to indicate I need to "broadcast" the new registry settings. Something to do with Windows SendMessage How do I do that from powershell? Do I need to do P/Invoke? Is there an easy way from within powershell? Karl |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Changing the PATH variable in the registry with Powershell A simpler method would be to add a line like this to your profile eg $env ath+=";C:\pathextra"-- Jon "meissnersd" <meissnersd@xxxxxx> wrote in message news:FA52D495-262A-434C-B0E2-A3CE151D8078@xxxxxx Quote: > It would be really nice to be able to manipulate the Path variable. > > Adding to the end of $env:Path will change the Path variable for the > session > of shell in powershell. But then your changes go poof when you close the > session. > > If you want to change the path permanently...you need to edit the > registry. > This is pretty easy to do. > > $original = (Get-ItemProperty > "HKLM:SYSTEM\CurrentControlSet\Control\Session Manager\Environment" Path > ).Path > > Set-ItemProperty "HKLM:SYSTEM\CurrentControlSet\Control\Session > Manager\Environment" Path -value ( $original + ";" + $dirname ) > > The issue is that registry settings are only read at login. > Starting a new powershell or cmd shell does not pick up the new settings > until I reboot. > When I google it seems to indicate I need to "broadcast" the new registry > settings. Something to do with Windows SendMessage > > How do I do that from powershell? Do I need to do P/Invoke? Is there an > easy way from within powershell? > > Karl > > > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Changing the PATH variable in the registry with Powershell well that would work for things within powershell. Tut I have tools and utilities which need the "real" path set which is why I need to set it in the registry. "Jon" wrote: Quote: > A simpler method would be to add a line like this to your profile eg > > $env ath+=";C:\pathextra"> > -- > Jon > > > "meissnersd" <meissnersd@xxxxxx> wrote in message > news:FA52D495-262A-434C-B0E2-A3CE151D8078@xxxxxx Quote: > > It would be really nice to be able to manipulate the Path variable. > > > > Adding to the end of $env:Path will change the Path variable for the > > session > > of shell in powershell. But then your changes go poof when you close the > > session. > > > > If you want to change the path permanently...you need to edit the > > registry. > > This is pretty easy to do. > > > > $original = (Get-ItemProperty > > "HKLM:SYSTEM\CurrentControlSet\Control\Session Manager\Environment" Path > > ).Path > > > > Set-ItemProperty "HKLM:SYSTEM\CurrentControlSet\Control\Session > > Manager\Environment" Path -value ( $original + ";" + $dirname ) > > > > The issue is that registry settings are only read at login. > > Starting a new powershell or cmd shell does not pick up the new settings > > until I reboot. > > When I google it seems to indicate I need to "broadcast" the new registry > > settings. Something to do with Windows SendMessage > > > > How do I do that from powershell? Do I need to do P/Invoke? Is there an > > easy way from within powershell? > > > > Karl > > > > > > > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Changing the PATH variable in the registry with Powershell "meissnersd" <meissnersd@xxxxxx> wrote in message news:7194743F-93EC-4505-9040-2D8DBE1BEAA7@xxxxxx Quote: > well that would work for things within powershell. > Tut I have tools and utilities which need the "real" path set which is why > I > need to set it in the registry. > You could use the static '[environment]::SetEnvironmentVariable' method, specifying an 'EnvironmentVariableTarget' as the third parameter eg an example setting an environment variable 'apples' [environment]::SetEnvironmentVariable("apples","three","User") [environment]::SetEnvironmentVariable("apples","three","Process") $env:apples OR [environment]::SetEnvironmentVariable("apples","three","Machine") [environment]::SetEnvironmentVariable("apples","three","Process") Similarly for the 'path' environment variable, but use with caution. cf EnvironmentVariableTarget Enumeration http://msdn2.microsoft.com/en-us/lib...et(VS.80).aspx -- Jon |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Changing the PATH variable in the registry with Powershell "meissnersd" <meissnersd@xxxxxx> wrote in message news:7194743F-93EC-4505-9040-2D8DBE1BEAA7@xxxxxx Quote: > well that would work for things within powershell. > Tut I have tools and utilities which need the "real" path set which is why > I > need to set it in the registry. > > > "Jon" wrote: > Quote: >> A simpler method would be to add a line like this to your profile eg >> >> $env ath+=";C:\pathextra">> tools and utilities invoked from that PowerShell session will get the updated path. That is, they will inherit PowerShell's process env block. -- Keith |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| spaces and variable in path | VB Script | |||
| Path Environment Variable - Vista 64-bit | Vista General | |||
| RE: Execute from command line with environment variable in path | PowerShell | |||
| Env. PATH variable not working sometimes... | Vista General | |||
| How can I ensure that a variable is a built-in powershell variable? | PowerShell | |||