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
  • 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.

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.


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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Filter IP range with PowerShell 1 40
Windows Password recovery 7 33
Slow Restore if incremental backups using RDiff.exe 4 17
Problem to setup GUI 11 26
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…
If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

815 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

8 Experts available now in Live!

Get 1:1 Help Now