Jump to content

update Path


Recommended Posts

Hi everybody !

Here is my pb : I want to update the Environment Path. So I do it by registry :

$s_OldPath = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment","PATH")

$sPathToAdd = "C:\TEMP"

RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment","PATH","REG_SZ",StringReplace($s_OldPath & ";" & $sPathToAdd,";;",";"))

EnvUpdate()

The Path is updated but (and it's a big pb) the system doesn't understand it.

I explain : my path (and all computers that I want to update) contains %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem

When I update the path through registry, the system cannot transform %SystemRoot% by it's real value (even after a roboot) so when I start a dos command and type path, it's not translated.

So you can see that nothing that needs the Path will work well after this.

Does someone know how to fix this issue (without replacing %SystemRoot% in the path) or to update the path correctly ?

Thanks in advance for your answers.

Link to comment
Share on other sites

Is %SystemRoot% defined? When you run the SET command from cmd, does %SystemRoot% return "C:\Windows" or whatever yours is?

that's my pb, %systemrrot% is defined but when I type path command from cmd it return %SystemRoot%.... and not the translated string as expected. So when I try to run a simple command like explorer, the system can't find it !

But is when I manually set the path by the system property windows (don't know the exact name in english) the path is correct and everything works. of course i try with the same string I put on the registry. I copy/paste it and it works...

I try with many different computer under 2 different OS : windows 2000 and windows Xp, with 2 different languages?

Am I the only one the get this pb?

Link to comment
Share on other sites

I have not seen this but I have only worked with English versions of Windows. Manually add the %SystemRoot% variable to a machine and reboot. This will override the built in one. Be careful to be sure it's pointing to the correct directory to avoid serious issues.

CODE
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "SystemRoot", "REG_SZ", 'C:\Windows')

Please let me know if this is a (temporary) solution.

Link to comment
Share on other sites

My suggestion would be to substitute the value of @WindowsDir for every occurrence of %SystemRoot%

and just write the Path with your string appended. It's only there to avoid hard coding the windows directory since they named some of them with NT and some without(and it may or may not be on C:). @WindowsDir accomplishes the same thing. If you had to substitute stuff particular to User accounts other variables may be problematic but it's not like somebody is going to keep changing where Windows was installed. As long as your script runs on the local machine it should be okay to do it that way.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...