Jump to content

Setting Environment Variables Using Batch


EuroFight

Recommended Posts

Hi everyone,

 

I am writing a batch script to be pushed out to systems that will modify the system 'Path' environment variable using the SETX command. My current code looks like this:

SETX Path "C:\Program Files (x86)\Internet Explorer\iexplore.exe;"+Path /M

pause

However, I wish to retain the current path variables as well as creating the new one. Is there a way to add to the variable instead of simply replacing it?

 

Thanks,

 

Euro

Share this post


Link to post
Share on other sites

Okay eventually I found a workaround, essentially I created a registry key containing the contents of 'Path' as well as my modified code

reg add HKCU\Temp /v SetEnvPathTemp /t reg_multi_sz /d "C:\Program Files (x86)\Internet Explorer\iexplore.exe;%Path%"

Then I exported the contents of the registry key to the path variable

setx Path /k "HKCU\Temp\SetEnvPathTemp" /M

It's a long way around it but it got the job done :thumbsup:

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...