Question Locked

Enviroment Variabes

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

i need to change the enviropment variable on multiple pc's (ahh easy you say) machines have different software installed on them, and i need to move a specific portion of the variables to a different location in the list

for example

C:\orant\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;c:\temp\;

and say i want to move c:\temp to before c:\orantbin like so

c:\temp\;C:\orant\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;

why i hear you ask
i have 2 software programs which are using the same dll names, the programs need to be in the correct order for them both to work correctly

any suggestions

7 replies

by Member 25348569

If you want to give yourself pain :)

FOR /F "tokens=1,2,3,4,5,6,7,8 delims=; " %%a in ("%path%") do set newpath=%%a;%%c;%%b;%%d;%%e;%%f;%%g;%%h
Set path =%newpath%

This will swap elements 2 and 3 and deal with a path of up to 8 elements. If you want to go beyond 26, you're stumped unless you use Khmer Windows... :p

Now, this won't stay set once the windows is closed so it's good for particular programs that need the path swapped for their environment only. You'll need Setx.exe to nail it in place. That's in the XPSP2 support tools http://www.microsoft.com/downloads/details.aspx?FamilyId=49AE8576-9BB9-4126-9761-BA8011FABF38&displaylang=en

Enjoy...

by craig.parkinson

script would be good except, i cant guarentee the sector of the variable i want to move will be in X location in the variable irt could in any place depending when it was installed, what was installed etc

looking at the setx commands (yep still looking) :-)

by Member 25348569

Set objShell = CreateObject("WScript.Shell")
Set objEnvironment = objShell.Enviroment("Process")
sPath = objEnvironment("PATH")

' So, we'd like to swap first with second if they're not already in that order

strFirst = "c:\put in front"
strSecond = "c:\put back"
aPath = Split(sPath,";")

For i = 0 To UBound(aPath)
If LCase(aPath(i)) = LCase(strFirst) Then iFirst = i
If LCase(aPath(i)) = LCase(strSecond) Then iSecond = i
Next

If iFirst > iSecond Then
stemp = aPath(iSecond)
aPath(iSecond) = aPath(iFirst)
aPath(iFirst) = sTemp
End If

sNewPath = aPath(0)

For i = 1 to uBound(aPath)
sNewPath = sNewPath & ";" & aPath(i)
Next

But, alas, you'll still need SETX to set it.

Do you have an vbscript skills? This would need some tweaking, checks to make sure that the two elements exist and so on.

Neil :)

by craig.parkinson

well vb stands for very basic in my dictionary im afraid, so basic i can run one and thats about it, more of a Dos person
could you not extract the contents of the reg file in HKLM\system\currentcontrolsset\control\sessionmanager\enviroment\path
search for the text required with in that reg file and delete it
i can add the appropriate program to the path at a later date

by Member 25348569

But I don't like recommending Registry Hacks to complete strangers. :p

strStringtoRemove ";c:\get rid of me"

Set WshShell = WScript.CreateObject("WScript.Shell")

strValPath = "HKLM\SYSTEM\currentcontrolsset\control\sessionmanager\enviroment\Path"

strValue = WshShell.RegRead(strValPath)

strNewValue = Replace(strValue,strStringtoRemove,"")

wshShell.RegWrite strValPath,strNewValue,"REG_EXPAND_SZ"

by craig.parkinson

will test this when back in the office monday (darn training fro 3 days)

This discussion is closed to new replies.