How to change %ProgramFiles% to D:\Program Files

sjbullock1981
sjbullock1981 used Ask the Experts™
on
Good Morning,
Firstly please excuse my igonorance windows scripting is not my strong point :)

I am trying to script an install of Teradata odbc, the install needs to be located in in D:\Program Files not C:\Program Files (All application specific installs need to be located in D:\Program Files).

When i use the following code:
      Set INSTALL_PATH=%SOURCEDIR%\FILES
      Set INSTALL_64=INSTALLDIR="D:\%PROGRAMFILES%"
      SET MSG=Running an install of Teradata GSS Client 64-bit
      %SOURCEDIR%\FILES\TeraGSS__windows_x8664.13.00.00.00\setup.exe /S "/v/qn %INSTALL_64%"
        SET ERRNUM=%ERRORLEVEL%
        IF %ERRNUM% EQU 3010 SET ERRNUM=0
        IF %ERRNUM% NEQ 0 GOTO ERROR

The Set INSTALL_64=INSTALLDIR="D:\%PROGRAMFILES%" command seems to try and set the INSTALL_64 to D:\C:\Program Files............Is there a way I can set %PROGRAMFILES% to D:\Program Files???

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Lee OsborneSenior Infrastructure Engineer

Commented:
You will need to reset the %programfiles% environment variable, as this is assigned to c:\program files .

That's why, when you use d:\%programfiles% it displays as d:\c:\program files

If you want to change the %programfiles% variable, use SET programfiles = "d:\program files" . Although, this isn't something I'd recommend.

Lee
Hey yea if you goto system in control panel then advanced the enviromental variables should be able todo it from there.
If you are just installing this application to d:\program files\ why not just code the full path in your script rather than using the %programfiles% vairable?
Test your restores, not your backups...
Top Expert 2016
Commented:
You could replace the C: in the existing PROGRAMFILES environment variable on the fly with D:.  I'd suggest something like this:

Set INSTALL_64=INSTALLDIR="%PROGRAMFILES:C:=D:%"

I'm not sure if you really want the double quotes around that in the SET either.  Keep in mind if you do it that way then the INSTALL_64 variable will actually have the surrounding quotes in it as part of the string.  So you might want to go with:

Set INSTALL_64=INSTALLDIR=%PROGRAMFILES:C:=D:%

And then when you reference the INSTALL_64 variable make sure you enclose it in quotes, like:

"%INSTALL_64%"

Just something else to watch out for, as long as you don't do both and end up with 2 double quotes on each end of the string you should be okay.

~bp
Ben Personick (Previously QCubed)Lead SaaS Infrastructure Engineer
Commented:
Not sure how your command ir going to run, there is a second set of double quote in it but I';m guessing you know the command's syntax better than I, here is the updated code for you, I took the liberty of doing a better error-level test as well.

Set "INSTALL_PATH=%SOURCEDIR%\FILES"
Set "INSTALL_64=INSTALLDIR="D:\%PROGRAMFILES:~2%""
SET "MSG=Running an install of Teradata GSS Client 64-bit"
"%SOURCEDIR%\FILES\TeraGSS__windows_x8664.13.00.00.00\setup.exe" /S "/v/qn %INSTALL_64%"
IF %ERRORLEVEL% NEQ 3010 ( GOTO ERROR ) ELSE ( SET ERRNUM=0 )

Open in new window


If you have problems you might really need this code here:

Set "INSTALL_PATH=%SOURCEDIR%\FILES"
Set "INSTALL_64=INSTALLDIR=D:\%PROGRAMFILES:~2%"
SET "MSG=Running an install of Teradata GSS Client 64-bit"
"%SOURCEDIR%\FILES\TeraGSS__windows_x8664.13.00.00.00\setup.exe" /S /v/qn "%INSTALL_64%"
IF %ERRORLEVEL% NEQ 3010 ( GOTO ERROR ) ELSE ( SET ERRNUM=0 )

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial