Environment Variables in ShortCut

Posted on 1997-12-15
Last Modified: 2013-12-29
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.

Question by:csilvest
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2

Expert Comment

ID: 1702669
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?
LVL 25

Expert Comment

ID: 1702670
Is the program Dos or 3.xx based or Windows 95?

Expert Comment

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

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.


Author Comment

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


Author Comment

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

LVL 14

Expert Comment

ID: 1702674
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.
LVL 25

Expert Comment

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

Author Comment

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

LVL 14

Accepted Solution

smeebud earned 100 total points
ID: 1702677
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.
LVL 25

Expert Comment

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


Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

This article summaries thoughts and ideas from two years of sustained use. It provides good reasoning to make the jump to Windows 10.
Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

624 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