Solved

Environment Variables in ShortCut

Posted on 1997-12-15
10
202 Views
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:

      C:\WINDOWS\PROGRAM.EXE %USERNAME%

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.

0
Comment
Question by:csilvest
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 8

Expert Comment

by:MaDdUCK
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?
0
 
LVL 25

Expert Comment

by:dew_associates
ID: 1702670
Is the program Dos or 3.xx based or Windows 95?
0
 
LVL 1

Expert Comment

by:ngpudding
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.

0
Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

 

Author Comment

by:csilvest
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.



0
 

Author Comment

by:csilvest
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.
 


0
 
LVL 14

Expert Comment

by:smeebud
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.
0
 
LVL 25

Expert Comment

by:dew_associates
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.
Dennis
0
 

Author Comment

by:csilvest
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 S:\A&B\%USERNAME%

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:

@ECHO OFF
IF (%USERNAME%)==() GOTO END
N:\A&B\A&B.EXE S:\A&B\%USERNAME%
:END

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






0
 
LVL 14

Accepted Solution

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

Expert Comment

by:dew_associates
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.


0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you try to extract and to view the contents of a Microsoft Update Standalone Package (MSU) for Windows Vista, you cannot extract the files from the MSU. Here we are going to explain how to extract those hotfix details without using any third pa…
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
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.

808 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