Jump to content

Creating a shortcut to %UserProfile% without expanding the variable


Recommended Posts

This is from the shortcut.exe documentation:

"To prevent an environment variable from being expanded until the shortcut is launched, use the ^ carat escape character like this: ^%WINDIR^%"

But when I try that (with userprofile env variable), all I get is a shortcut to C:\^%UserProfile^%

I also tried %%UserProfile%% and I got C:\%C:\Documents and Settings\Administrator%\Application Data

What is the correct way to do it?

Link to comment
Share on other sites


Ye note the second attempt, with the double %% signs, is correct, ectept ye do not need to prefix the drive, viz

%%userprofile%%

You should note under Windows Vista ye get different variables, because vista moved all of the common locations.

Here is win2k, on my box.

[I:\]
set h
HOMEDRIVE=I:
HOMEPATH=\

[I:\]set u
USERDOMAIN=PENNING
USERNAME=wendy
USERPROFILE=I:\USERS\wendy

[I:\]

note here that userprofile points to the location of the user profile (NTUSER.DAT). which is usually located in the root of the home directory.

HOMEDRIVE and HOMEPATH could point to directories where the user data is stored.

None the same, this worked.

[I:\]cd %userprofile%

[I:\USERS\wendy]"shortcut" -n homedir.lnk -t explorer.exe -a /e,%%Userprofile%%

[I:\USERS\wendy]"shortcut" homedir.lnk -u all
LinkName: homedir.lnk
Arguments: /e,%Userprofile%
Target: I:\FENSTER\explorer.exe
Working Directory: <none>
Icon File: <none>
Icon Index: 0

shortcut is from the NT4 reskit, is an NT version of the 95 utility.

Edited by os2fan2
Link to comment
Share on other sites

No, this shortcut.exe is not from the resource kit. It's from http://www.optimumx.com/download/
I had tried the shortcut.exe utility some time ago. I opted not to use it because it generated invalid shortcuts (Windows often corrected the shortcut problems on run, however).

If you want a utility to generated shortcuts, I would recommend XXMKLINK ( http://www.xxcopy.com/xxcopy38.htm ). It uses double a "%" charcter on each side of an evironmental variable to include the variable in the shortcut (example %%SystemDrive%% or %%SystemRoot%%).

Link to comment
Share on other sites

Have you thought about using a VBS script to make the shortcuts.

This script makes a shortcut for Calculator and places it in the quicklaunch folder

Save as QL_CalcSC.vbs

Dim Act, ObjSC, QuickLaunch, StrCalc
Set Act = CreateObject("WScript.Shell")
QuickLaunch = Act.ExpandEnvironmentStrings("%AppData%\Microsoft\Internet Explorer\Quick Launch")
StrCalc = Act.ExpandEnvironmentStrings("%SystemRoot%\system32\calc.exe")
Set ObjSC = Act.CreateShortcut(QuickLaunch & "\Calc.lnk")
ObjSC.Description = Act.ExpandEnvironmentStrings("%UserName%") & " Open Calc.exe"
ObjSC.TargetPath = StrCalc
ObjSC.Save

Link to comment
Share on other sites

The utility as you stated does seem to incorrectly exhibit this behaviour; you have done nothing wrong, the utility is in error.

shortcut.exe /f:"%UserProfile%\Application Data.lnk" /a:C /t:"^%UserProfile^%\Application Data"
Why though would you want to create a shortcut to the Users Application Data folder and store it inside the Users Application Data folder and give it the name Application Data?

It can be done, I have done so successfully, however since its only purpose would be to act as a `directory refresh` I see little point in uploading my solution. If you'd like to give us a real example of what exactly it is you want I'll see what I can do to help you further.

Link to comment
Share on other sites

No it would be a link to the app data from the profile. When files are hidden, you can't browse to the app data folder. With the shortcut in the profile, you can (without having to type in the address bar or showing hidden files). Just a small tweak I like.

Link to comment
Share on other sites

Okay, I understand your reasoning for the location in %userprofile%, as opposed to the %appdata% folder you gave in your example.

Try the compiled batch file in the archive below.

Its content is one single .cmd file, there is no third party utility included or required.

Due to the nature of the compilation and the hidden window Anti-Malware programs may not like this file.

Please judge for yourself whether you wish to run it!

_AppData.zip

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...