Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Create a shortcut via a relative path

Posted on 2006-06-12
13
Medium Priority
?
1,767 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Can I legally transfer my OEM version of Windows to another PC?  (AKA - Can I put a new systemboard in my OEM PC?) Few of us are both IT and legal experts but we all have our own views of Microsoft's licensing rules and how they apply.  There are…
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

783 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