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\O rc.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(sSho rtcutPath)
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_08551 5-Shortcut to Orc.lnk
Deleting Shortcut to Orc.lnk
Creating New Orc Shortcut...
Path to Orc O:\Orc5.2.15.app\Contents\ Windows\Or c.exe
Target Path O:\Orc5.app\Contents\Windo ws\Orc.exe
c:\windows\system32\cscrip t 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,
Code Snippets
sDesktop = "c:\Documents and Settings\trader\desktop"
sPathToOrc = "O:\Orc5.2.15.app\Contents
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(sSho
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_08551
Deleting Shortcut to Orc.lnk
Creating New Orc Shortcut...
Path to Orc O:\Orc5.2.15.app\Contents\
Target Path O:\Orc5.app\Contents\Windo
c:\windows\system32\cscrip
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,
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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.Fi leSystemOb ject")
Set wshNetwork = CreateObject("WScript.Netw ork")
Set objShell = CreateObject("WScript.Shel l")
If objFSO.DriveExists("O:") = True Then
wshNetwork.DisconnectNetwo rkDrive("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.
You could also use the following to check for the O Drive already, before the subst:
'===================
Set objFSO = CreateObject("Scripting.Fi
Set wshNetwork = CreateObject("WScript.Netw
Set objShell = CreateObject("WScript.Shel
If objFSO.DriveExists("O:") = True Then
wshNetwork.DisconnectNetwo
End If
objShell.Run "subst o: c:\", 0, True
' ....create TargetPath
objShell.Run "Subst o: /del", 0, True
wshNetwork.MapNetworkDrive
'================
Regards,
Rob.
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!
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.
Anyway, I learnt something too, so it's all good!
Rob.
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.