Jump to content

Shortcut with environment variable


Recommended Posts

The thing is: RunOnceEX installs Mozilla and Firefox through a 7zip SFX archive, which saves space and is easy in use. But I want shortcuts on the desktop. And I'd like the shortcut to refer to %programfiles%\... , this doesn't work as environment variables aren't supported in shortcuts...

Is there a work-around?

Link to comment
Share on other sites


It should work.  Maybe the 7z archive is messing it up.  I made an NSIS installer for mozilla.  You could do the same, and make a shortcut with the variables.

hmmm... Didn't think of that; didn't think of making an installer myself :) Thanks for the idea, I'll try it tomorrow!

Link to comment
Share on other sites

FYI to those that don't know - to see the variables that available - type SET at a cmd prompt.

There are also a couple more that you won't see there. type set /? at the bottom of all that info are a couple more.

Link to comment
Share on other sites

Guest zippy

right-click on the shortcut of notepad in start menu, then open properties, you can find 3 env.variables.

but env.vars on RunOnce are not all available as ready system. you can make a dump during RunOnce, SET>%SystemDrive%\env.log, to find out which env.vars available that time.

.\Util.EXE -y -o"%ProgramFiles%"
.\UtilLink.EXE -y -o"%ALLUSERSPROFILE%\Desktop"

that's what i do in RunOnce, they are both 7-zip console sfx archive.

first one extracts some program executables.

2nd one extracts shortcuts for those programs. all shortcuts using %ProgramFiles% to refer to where it is.

maybe you just forgot to enclose output directory with double quotes...

Link to comment
Share on other sites

I wrote the following script to change all the shortcut to point to %ProgramFiles%: (change the folder in the Find call)

Set WshShell = CreateObject("WScript.Shell") 
Set fso = CreateObject("Scripting.FileSystemObject")

kProgFiles = "\Program Files\"
lProgFilesLen = Len(kProgFiles)
EnvProgramFiles = "%ProgramFiles%"

Find "FILESCD\$OEM$\$1\InstallFolders", "lnk"

Function Find (strPath, strFileExt)
Dim MyDir, MyFile, MySubDir

If strFileExt = Empty Then Exit Function
strFileExt = Ucase(strFileExt)

Set MyDir = fso.GetFolder(strPath)

For Each MyFile In MyDir.Files
 If UCase(Right(MyFile.Name, 3)) = strFileExt Then ChangePath strPath & "\" & MyFile.Name
Next

For Each MySubDir In MyDir.SubFolders
 Find strPath & "\" & MySubDir.Name, strFileExt
Next
End Function

Function ChangePath(OldName)
   NewName = OldName & ".NEW.lnk"
   
   Set ExistLink = fso.GetFile(OldName)
   Set NewLink = WshShell.CreateShortcut(NewName)
   NewLink.Save
   ExistLink.Copy NewName, True
   
   Set NewLink = WshShell.CreateShortcut(NewName)
   NewTargetPath = NewLink.TargetPath
   NewIconLocation = NewLink.IconLocation
   NewWorkingDirectory = NewLink.WorkingDirectory
   NewArguments = NewLink.Arguments
   NewDescription = NewLink.Description
   
   NewLink.TargetPath = ChangeProgFiles(NewTargetPath)
   NewLink.IconLocation = ChangeProgFiles(NewIconLocation)
   NewLink.WorkingDirectory = ChangeProgFiles(NewWorkingDirectory)
   NewLink.Arguments = ChangeProgFiles(NewArguments)
   NewLink.Description = ChangeProgFiles(NewDescription)
   
   NewLink.Save
   ExistLink.Delete
   fso.MoveFile NewName, OldName
End Function

Function ChangeProgFiles(sPath)
   ChangeProgFiles = sPath
   If Mid(sPath,3,lProgFilesLen) = kProgFiles Then ChangeProgFiles = EnvProgramFiles & Mid(sPath,2 + lProgFilesLen)
'   MsgBox "Old  =" & sPath & vbCrLf & "New=" & ChangeProgFiles
End Function

This .vbschanges all x:\Program Files to %ProgramFiles% (in TargetPath, IconLocation, WorkingDirectory, Arguments and Description)

Link to comment
Share on other sites

right-click on the shortcut of notepad in start menu, then open properties, you can find 3 env.variables.

but env.vars on RunOnce are not all available as ready system. you can make a dump during RunOnce, SET>%SystemDrive%\env.log, to find out which env.vars available that time.

.\Util.EXE -y -o"%ProgramFiles%"
.\UtilLink.EXE -y -o"%ALLUSERSPROFILE%\Desktop"

that's what i do in RunOnce, they are both 7-zip console sfx archive.

first one extracts some program executables.

2nd one extracts shortcuts for those programs. all shortcuts using %ProgramFiles% to refer to where it is.

maybe you just forgot to enclose output directory with double quotes...

This was EXACTLY what I was looking for! Thank you!

(Just for the record, why doesn't Windows have a built-in alike feature?)

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