Solved

Create a shortcut via a relative path

Posted on 2006-06-12
13
1,757 Views
Last Modified: 2008-01-16
I have a USB key chain drive that I use on various computers.  On each computer the drive letter is different.  How can I create a shortcut on the USB to point to a file releative to where I place the shortcut?

Ex. USB Driver: F:\

File path F:\ABC\123\text.txt

Would like relative path if running shortcut from F:\ABC

"\123\text.txt"  XP would permit this shotcut

Thank you.
0
Comment
Question by:thandel
  • 6
  • 6
13 Comments
 
LVL 9

Expert Comment

by:AndreDekolta
ID: 16887271
Hello thandel!

Each system would interpret it differently.  This is an XP weakness in the way it opens/reads UBS drives/ports, etc.  So, you would have to keep changing the shortcut on each system.  Sucks doesn't it!  I would like to do the same thing for my very administrative duties.  I have found some third party software.  But, you'd have to install it every system.  Not practical in my case since I have over 200 systems.

Andre...
0
 

Author Comment

by:thandel
ID: 16887402
I would think a short cut could be setup as you can do it from a DOS command.

One solution I was thinking about was simply a DOS batch file that runs and trys letters until it is sucessfull.
0
 
LVL 4

Expert Comment

by:yesplease151
ID: 16887489
You can do a vbscript.  Smoething like this will give you the current folder:

Dim LaunchDir, FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
LaunchDir = FSO.GetFolder(".")
msgbox(LaunchDir)

So I guess you could do this:

Dim LaunchDir, FSO, WSHShell
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WSHShell = WScript.CreateObject("WScript.Shell")
LaunchDir = FSO.GetFolder(".")

wSHShell.Run LaunchDir & "\123\text.txt"
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:thandel
ID: 16887560
Tried that but I am getting an error on the last line that it can't find the file.  I should have been more specific as the shortcut points to a folder I'm trying to open.  Sorry about that.
0
 

Author Comment

by:thandel
ID: 16887647
OK I seems to not be working because of spaces in the path... how can this be resolved?  I tried %20% but I didn't work so I must have that wrong.
0
 
LVL 4

Expert Comment

by:yesplease151
ID: 16887655
Can you post the full path?
0
 

Author Comment

by:thandel
ID: 16887670
wSHShell.Run LaunchDir & "\HSEC\Documents and Settings\Todd\My Documents"
0
 
LVL 4

Expert Comment

by:yesplease151
ID: 16887717
Oh, opening a directory is different.  Here you go...

Dim LaunchDir, FSO, WSHShell
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WSHShell = WScript.CreateObject("Shell.Application")
LaunchDir = FSO.GetFolder(".")

wSHShell.Open LaunchDir & "\HSEC\Documents and Settings\Todd\My Documents"
0
 

Author Comment

by:thandel
ID: 16887766
Well two observations.

You last code does not return an error any more but it also does nothing either.  I doesn't open a window or anything.

Second, the original code was also getting an error even when I tried to open a file.  It DID work when I tried: wSHShell.Open LaunchDir & "\HSEC\"


So I think the first code would wroke if the spaces in the full path can be resolved.
0
 
LVL 4

Accepted Solution

by:
yesplease151 earned 125 total points
ID: 16888050
Remove the \ before HSEC.  If you are running it from the root of the drive, it should not have the \.   If that doesn't work, insert a message box before the last line and let me know what it says.

msgbox(LaunchDir & "\HSEC\Documents and Settings\Todd\My Documents")
0
 
LVL 4

Expert Comment

by:yesplease151
ID: 16888055
Spaces in the path do not matter.  It can run with the spaces.
0
 

Author Comment

by:thandel
ID: 16888106
Thankts that was it... final working code:

Dim LaunchDir, FSO, WSHShell
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WSHShell = WScript.CreateObject("Shell.Application")
LaunchDir = FSO.GetFolder(".")

wSHShell.Open LaunchDir & "HSEC\Documents and Settings\Todd\My Documents"


0
 
LVL 4

Expert Comment

by:yesplease151
ID: 16888164
Great.  The reason it originally had the \ was because it was being run from F:\ABC.

Hope it works well for you.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Suggested Solutions

Title # Comments Views Activity
Incredibly nasty malware/adware 15 71
Lock down IT Intern accounts 4 124
Exe program is not a valid Win 32 application 15 117
Windows print sharing 1 81
Disclosure: Use this tutorial only when no other options helps to get Windows XP running without any problems and you don't want to format the drive. The back up of the data is the responsible of the user, however there is a description of how t…
Migration of Exchange mailbox can be done with the ExProfre.exe tool. But at times, when the ExProfre.exe tool migrates the Exchange Server user profile, it results in numerous synchronization problems. Synchronization error messages appear in the e…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

679 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