Environment Variables in ShortCut

I need to put an environment variable in a ShortCut's Target" field. In Windows 3.x, I would put (in the "Command Line" field) something like:


where the %USERNAME% is the environment variable.  This variable would be expanded into the current value.  This was very handy for running programs based on who is currently using the computer, among other things.

Putting this sort of variable in Windows 95's ShortCut -> Target field results in the test "%USERNAME%" being passed to the program.  IOW, the variable name is not being replaced.

Any help would be appreciated.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Works fine with me. Try the following: open the run windows in the start menu and just enter %username%. If it says file not found, then you environment variable is not defined and you have to reinstall the networking component.

Hope this helps.

PS Why did you post twice?
Is the program Dos or 3.xx based or Windows 95?
Maybe you can try enclosing the whole target string in double quotes, making it look like : "C:\WINDOWS\PROGRAM.EXE %USERNAME%"
This will make Win95 recognize it as a single string.

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

csilvestAuthor Commented:
dew_associates: The program is a Windows 3.x program.

ngpudding: Tried enclosing the whole string in the "Target" field in quotes, as in:

Target: "N:\A&B\A&B.EXE S:\A&B\%USERNAME%"

This gives a message "The name in the target field is not valid".

Putting quotes around just the argument part:

Target: N:\A&B\A&B.EXE "S:\A&B\%USERNAME%"
doesn't work either, behaves just as if there were no quotes.

csilvestAuthor Commented:
MaDduck: If I enter the %USERNAME% in Start -> Run, I get the error:

"Cannot find the file %USERNAME% (or one of its components). Make sure the path and filename..."

USERNAME _is_ defined... if I open a DOS prompt and enter SET, USERNAME is defined and has a value.

Why did I post twice?  Beats me.  I don't think I intended to do so... I'm a newbie at this Expert Exchange thing, I probably did something wrong.

Go to My Computer|View|Options|File Types.
1. There Create a new association for your program.
2. Then click edit and in the action box type 'open' no qoutes.
3. In the "Application to perform this action" put your Command line then ok your way out.
Okay, time to get down to specifics here!
CSilvest, if possible, post what your trying to run and the variables that you want to plug in and maybe we can come up with what you want. In essence, we need to know the type of variables you want to load. This will enable us to develop something within 95 for a 3.xx based program.
csilvestAuthor Commented:
dew associates:  All the pertinent info is posted.  It's a Windows 3.x application called Above & Beyond.  In Windows 3.x, I create an icon, and in the Command Line field of the icon's properties I would put:


N:\A&B\A&B.EXE is the name of the application's executable.

%USERNAME% is an environment variable set during the login script to the user's name.  In my case, it would be CEDRIC-S

S:\A&B\CEDRIC-S is a directory that I want Above & Beyond to store all it's data files.  Every user on our network has a directory below S:\A&B, and the name of the directory is the same as their username.

In Windows 3.x, when the icon is double-clicked, OR it is run because it is in the Startup group, everything works correctly, because Windows 3.x sees the %USERNAME% and substitutes the name of the user for it.

In Windows 95, this substitution doesn't happen.  Above & Beyond gets the argument S:\A&B\%USERNAME% and tries to locate its data files in S:\A&B\%USERNAME%, a non-existant directory.

I have been able to make it work by using a batch file, such as:


However, I'd really like a pure Windows 95 solution.

I know you rejected this answer. I need to know why before I can help you. This is the closest to a "pure Windows 95 solution"
that I can think of without some feedback from you.
Go to My Computer|View|Options|File Types.
1. There Create a new association for your program.
2. Then click edit and in the action box type 'open' no qoutes.
3. In the "Application to perform this action" put your Command line
then ok your way out.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Actually, you have already handled the problem in one of the two methods suggested by Microsoft. The other would be slightly more difficult and would be the pure solution your looking for. Here's why though! Neither a 32-bit compiled application nor solution code called from a 32-bit application can make direct 16-bit API or DLL calls. In addition, neither a 16-bit compiled application nor solution code called from a 16-bit application can make direct 32-bit API or DLL calls. This inability to make calls back and forth between 16-bit and 32-bit layers occurs in both the Windows 95 and Windows NT environments because of their advanced flat-memory-model management systems, as well as the way in which they load DLLs.
To prepare your program for Win 95, you must change your solution code to make Win32 API calls when the solution code is executed from 32-bit applications such as Windows 95. If this is not possible (for example, you don't have access to the source code of the DLL), you must change the solution code to thunk through an intermediate DLL to make the 16-bit API call. Updating a solution code to support Win32 API calls is a relatively simple mechanical process, but a more significant task is to write code that is operating-system-independent. Microsoft suggests in such situations, rather than to rewrite code to support Win32 API calls from Win 3.xx based applications being executed in Win95, the user attempt to resolve the issues by creating an application dependent DLL or adjust variables through the use of batch files. Obviously, you have already found that you can accomplish this task with the use of a batch file.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows OS

From novice to tech pro — start learning today.