Solved

Create a shortcut via a relative path

Posted on 2006-06-12
13
1,753 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
 

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

If you build your web application in Visual Studio you'll get at least a few binaries, or .DLL, files in your bin folder. However, there is more compiling to be done. Normally this would happen when an ASP.NET resource within the web site is request…
Are you unable to synchronize your OST (Offline Storage Table) file with Microsoft Exchange Server? Is your OST file exceeding 2 GB size limit? In Microsoft Outlook 2002 and earlier versions, there is a 2 GB size limit for the OST file. If the file …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

13 Experts available now in Live!

Get 1:1 Help Now