System variable %ProgramFiles% is not listed with the other variables and I want to change it (temporarily)

Posted on 2006-05-05
Last Modified: 2008-01-09
I am making batch files, telling the main script to put %PROGRAMFILES%
in the script. However, because my systems variable is %PROGRAMFILES%
and that is the environment I am doing this in - it is putting........

C:\Program Files

There instead of just.........


So I need to alter my system variable so that
%PROGRAMFILES% does not exist on my system,
only temporarily whilst I do this, then I will change
it back to normal again (%PROGRAMFILES%)

I have looked in Control Panel > System > Advanced (tab) > Environment Variables (button)
and under that window, it does not show %PROGRAMFILES% anywhere. "C:\Program Files"
is referred to along the line that simply says "Path". WHAT?! What the hell is that?

If I change that "Path" then it will mess up......

C:\Program Files -- (%PROGRAMFILES%) but I WANT TO mess this one up! Temporarily, of course!

ALL the above are under "Path".

Hmmmmmmmmmm, thats strange because I do not have the variable %PATH%
that controls 4 things, do I? I certainly hope not.

So where can I change %PROGRAMFILES% to something like %PROGRAM_FILES%
just whilst I create these files with %PROGRAMFILES% in then and not "C:\Program Files".

Its no use because Windows is not ALWAYS installed to a C drive.
In a lot of cases, especially corporate organisations, Windows might
be on any drive BUT the C drive, for security etc. I can't believe it just
puts the full path instead of the variable when I told it to put the variable!

It makes me MAD!

So, now I have to change MY environment variable on my system and
risk messing that up just to put %PROGRAMFILES% in?! Sheesh honestly,
unless anyone knows of a special character I can use but that is out of
the question, it means making all the scripts all over again :(
Question by:EE33
    LVL 95

    Assisted Solution

    by:Lee W, MVP
    You need to be conscious of the various environment variables that are already set.  How many batch files do you have?  What's the big deal changing the batch files - use "%progfiles%" instead of "%programfiles%"  Open the files up and do a find/replace.  Write a vbscript to globally replace all instances in all files.  Won't take that long.
    LVL 5

    Accepted Solution

    I would recommend against trying to modify the system variable name %PROGRAMFILES% to anything else.

    If you use a program called EditPad you can search/replace multiple text file entries at one time, so changing 30 batch files' that have %programfiles% to now say %progfiles% takes under a minute.

    To see what environment variables Windows is using you can go to a command prompt asnd type SET. If you want this output captured in a file type SET > C:\winsettings.txt and the file winsettings.txt wil lbe created in the root of C:

    Can you post an example of a batch you're creating with the %programfiles% file here? I'm Interested in seeing the end result you're looking for.
    LVL 15

    Assisted Solution

    you can set the variable temporarily in the command window like

    set programfiles=mynewvalue

    check it with
    echo %programfiles%

    it is only set for that command window session (so you dont have to worry about it overwriting your persistent setting)
    LVL 24

    Assisted Solution

    Batch files always expand %variablename% to the value of the variable. If you do not want it to, you have to use double %%.
    The following in a batch file will echo the vaule of blah, the word "boo"
    set blah=boo
    echo %blah%

    However, adding 2 more %s as in....
    set blah=boo
    echo %%blah%%
    will result in the actual echo of "%blah%"

    "I can't believe it just puts the full path instead of the variable when I told it to put the variable!"
    That's because you didn't tell it to put the variable. %variable% syntax in a batch file is telling it to EXPAND the variable. Using %%variable%% syntax in a batch file is telling it to put the %variable% itself.

    That is why when you use %programfiles% in a batch file it gets expanded to whatever is in the value "ProgramFilesDir" under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion

    I do NOT recommend changing "ProgamFilesPath" in that same registry key, as there are many references in the registry that do use %programfiles% syntax.

    Your best bet as already mentioned is to change your batch files to use another variable name.
    LVL 3

    Author Comment

    Every single answer has helped equally here!!

    leew - I changed %PROGRAMFILES% to %PROGFILES%
    and it didn't show up at all in the BAT file (it started with \Folder
    instead of %PROGFILES%\Folder) but I can't guarantee I am
    even doing it right when I have this stupid GAP at the start of
    all the scripts!

    The_IT_Garage - same thing with the %PROGFILES%.
    You prompted me to have another go at what I initially
    thought, change all the files replacing the text in them,
    but they needed renaming to TXT first. I have renamed
    them (REN *.BAT *.txt) and ......

    Oh lordy I found an incredible FREEWARE program
    to change the text in text files!!

    Replace in Files 1.01...,replace-in-files,dl.html

    With this I can:

    Change [C:\Program Files] to [%PROGRAMFILES%]
    Change [C:\WINDOWS] to [%WINDIR%]

    And most of all take that stupid gap
    out I never did fix in my other question!

    dave4dl - you "answered correctly" the question
    I was "asking" even though I found a better way,
    this is it I mean, should these points be split 125 each?

    Kenneniah - you answered too - the double variable,
    or variable inside a variable?) anyway you also answered
    and said use a text editor!

    So, all 4 answers are right..... I found the (%100% free) program myself though :P

    LVL 3

    Author Comment

    For people wondering what i'm doing, I can't
    tell you! But this involves over two thousand
    batch files... now you see why I want to avoid
    manually editing them!

    If what I am doing takes off, you'll see it whenever
    it gets fully finished and released :$ if it ever does.
    LVL 3

    Author Comment

    In fact that REPLALL.EXE (Replace in Files) is only 68Kb and just runs
    (it has no install) its just there as a working executable :D and totally free!
    LVL 24

    Expert Comment

    The reason %PROGFILES%\Folder becomes just \Folder when used in a batch file comes from the reason I mentioned before, just slightly different. Anything between single %s is treated as a variable by a batch file. So the batch files are expanding %PROGFILES% like a variable, but I'm from the results I'm guessing that that progfiles has never been initialised with information (as in a "set progfiles=something") it is treated as an empty variable.

    Anyway, hope it works out for you and thanks for the points :)
    LVL 5

    Expert Comment

    Thanks for the points!

    1000 .BAT files? You know Excel can be used in a pinch to create batch files if you have say, a list of 1000 computers and you need to do something with them, like perhaps turn off and stop a service on a bunch of servers. Any time you have a command that is for example:
    psservice \\<servername> messengerservice stop

    column A is psservice column B will be your list of server names, column C is setconfig messenger disabled and column D is bascailly A&B&C&D (add spaces as needed until D comes out looking right). Then you cut and paste column D into a .BAT and presto, batch file to stop the messenger service on 1000 machines and you created it in about a minute and when you run it it MIGHT take 5 more minutes.

    Just an example as I don't know what you're creating batch files for but keep in mind Excel can save a TON of time in some cases.
    LVL 5

    Expert Comment

    "column C is setconfig messenger disabled"  Oops I mean C is messengerservice stop...but you still get the idea...

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Can I legally transfer my OEM version of Windows to another PC?  (AKA - Can I put a new systemboard in my OEM PC?) Few of us are both IT and legal experts but we all have our own views of Microsoft's licensing rules and how they apply.  There are…
    Step by step guide to Clean and Sort your windows registry! Introduction: Always remember: A Clean registry = Better performance = Save your invaluable time In this article we're going to clear our registry manually! Yes, manually! The e…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now