Solved

Create a shortcut via a relative path

Posted on 2006-06-12
13
1,754 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Printing outside margins from DOS 16 145
Backup Window XP mode 6 120
Copy and Paste Windows 7 Files Not Working 6 92
Event ID: 5719 / Source: NETLOGON 9 103
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 …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

911 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

16 Experts available now in Live!

Get 1:1 Help Now