Solved

Environment Variables in ShortCut

Posted on 1997-12-15
10
196 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
 

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
Why spend so long doing email signature updates?

Do you spend loads of your time carrying out email signature updates? Not very interesting are they? Don’t let signature updates get you down. Let Exclaimer Cloud - Signatures for Office 365 make managing email signatures a breeze.

 
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

The curse of the end user strikes again      

You’ve updated all your end user’s email signatures. Hooray! But guess what? They’re playing around with the HTML, adding stupid taglines and ruining the imagery. Find out how you can save your signatures from end users today.

Join & Write a Comment

Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
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…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

757 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

21 Experts available now in Live!

Get 1:1 Help Now