We help IT Professionals succeed at work.

Windows Scripting - Problem creating a desktop shortcut

yt-flc
yt-flc asked
on
878 Views
Last Modified: 2008-04-24
Hi all - I'm writing a script that updates a shortcut to one of the App we use when we are upgrading versions.

Code Snippets

sDesktop = "c:\Documents and Settings\trader\desktop"

sPathToOrc = "O:\Orc5.2.15.app\Contents\Windows\Orc.exe"
sShortCutDescription = "Shortcut to Orc"
sShortcutPath = sDesktop & "\Shortcut to Orc.lnk"
sShortcutBackupDir = "Orc Shortcuts"

'logic to backup old shortcut cut....

wscript.echo ("Creating New Orc Shortcut...")
Set oNewSC = oShell.CreateShortcut(sShortcutPath)
wscript.echo "Path to Orc " & sPathToOrc
oNewSC.TargetPath = sPathToOrc
wscript.echo "Target Path " & oNewSC.TargetPath
oNewSC.Description = sShortcutDescription
oNewSC.Save

Now the problem is that the new shortcut Target Path is getting
mangled for some reason - you can see it in the output below.

Found Orc Shortcut: Shortcut to Orc.lnk
Copying Shortcut to Orc.lnk to c:\Documents and Settings\trader\desktop
\Orc Shortcuts\2007-06-08_085515-Shortcut to Orc.lnk
Deleting Shortcut to Orc.lnk
Creating New Orc Shortcut...
Path to Orc O:\Orc5.2.15.app\Contents\Windows\Orc.exe
Target Path O:\Orc5.app\Contents\Windows\Orc.exe
c:\windows\system32\cscript exited on desk15-big with error code 0.

Its dropping the 2.15 - why is this happening?  It works fine on my
local machine, but when I run it from my machine on the remote PC with psexec it messes up the path.

Thanks,
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
I'm not entirely sure, that's a strange one, but try either
1) use a Save command after assigning the targetpath
oNewSC.TargetPath = sPathToOrc
oNewSC.Save
wscript.echo "Target Path " & oNewSC.TargetPath

2) Have a read of this article:
The Create Shortcut command truncates the source path folder names to eight characters
http://support.microsoft.com/kb/263324

Regards,

Rob.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thank Rob, I won't be able to try these for a couple of days (long weekend just kicked off) but Ill let you know when I get back to work.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Yeah, I was on a long weekend myself, Queen's B'day in Vic, Australia.
You could also use the following to check for the O Drive already, before the subst:
'===================
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wshNetwork = CreateObject("WScript.Network")
Set objShell = CreateObject("WScript.Shell")
If objFSO.DriveExists("O:") = True Then
   wshNetwork.DisconnectNetworkDrive("O:")
End If
objShell.Run "subst o: c:\", 0, True
   '  ....create TargetPath
objShell.Run "Subst o: /del", 0, True
wshNetwork.MapNetworkDrive("O:", "\\server\share")
'================

Regards,

Rob.

Author

Commented:
Well, looks like you were on the right track Rob.  I added a simple

oShell.Run "subst o: c:\", 0, True before
and
oShell.Run "Subst o: /del", 0, True after

the creation of the shortcut and it now works properly.  I didn't seem to need to disconnect the network drive either (!).  I might investigate that a little further, but it works for now.

Cheers!
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Great!  That really weird about not having to disconnect O drive first!  I just tried using Subst n: C:\ and I already have an N drive, and it said invalid parameter.  When I disconnected N manually and then did the same subst command it worked, so I'm REALLY surprised that the scripted subst allowed it to work!

Anyway, I learnt something too, so it's all good!

Rob.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.