Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Posted on 2006-05-05
Medium Priority
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
  • 3
  • 3
  • 2
  • +2
LVL 97

Assisted Solution

by:Lee W, MVP
Lee W, MVP earned 500 total points
ID: 16616562
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.

Accepted Solution

The_IT_Garage earned 500 total points
ID: 16616984
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

dave4dl earned 500 total points
ID: 16616991
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)
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 24

Assisted Solution

Kenneniah earned 500 total points
ID: 16618629
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.

Author Comment

ID: 16619097
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...

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


Author Comment

ID: 16619104
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.

Author Comment

ID: 16619136
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

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

Expert Comment

ID: 16620218
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.

Expert Comment

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Can you find a fax from a vendor you saved a decade ago in seconds? Have you ever cursed your PC under your breath during an audit because you couldn’t find the requested statement or driver history?  If you answered no to the first question or yes …
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

580 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