Link to home
Create AccountLog in
Avatar of yt-flc
yt-flc

asked on

Windows Scripting - Problem creating a desktop shortcut

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,
Avatar of RobSampson
RobSampson
Flag of Australia image

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.
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of yt-flc
yt-flc

ASKER

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.
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.
Avatar of yt-flc

ASKER

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!
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.