Jump to content

Creating a shortcut to %UserProfile% without expanding the variable


Recommended Posts

Posted

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?


Posted (edited)

maybe try

"^%windir^%" with quotes? maybe try double quotes? paste more of the code your using?

Edited by MCT
Posted (edited)

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
Posted
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%%).

Posted

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

Posted

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.

Posted

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.

Posted

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

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