Enviroment Variabes

By craig.parkinson ·
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


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


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

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

Well, I'd do it with a vbscript but...

by neilb@uk In reply to Enviroment Variabes

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...

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


Collapse -

i would but......

by craig.parkinson In reply to Well, I'd do it with a vb ...

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) :-)

Collapse -

A vbscript would be relatively easy

by neilb@uk In reply to i would but......

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

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)

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 :)

Collapse -

vb skills

by craig.parkinson In reply to A vbscript would be relat ...

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

Collapse -

Well, yes

by neilb@uk In reply to vb skills

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

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"

Collapse -

well thanks

by craig.parkinson In reply to Well, yes

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

Related Discussions

Related Forums