Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command Line error when creating shortcut on desktop

Status
Not open for further replies.

conan3

MIS
May 6, 2003
65
US
The problem is this when I create a desktop shortcut with a complex command line below it does not work. Seems the shortcut is changed some how. The echo of the command line is correct, But the shortcut is not????

A less complex command line works just fine..

Anyone have any ideas????



1.) Original Desktop Short Cut Works fine

"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" \\MyServer\Projects\RecallRoster_User\Application\Recallroster.mde /wrkgrp "\\MyServer\Projects\RecallRoster_User\Application\SecureRecall.mdw" /x "command-line"


2.) VBSCRIPT Created Shortcut does not work, it drops first backslash on path and flips backslash on X just before “command-line”

"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" \MyServer\Projects\RecallRoster_User\Application\Recallroster.mde \wrkgrp "\MyServer\Projects\RecallRoster_User\Application\SecureRecall.mdw" \x "command-line"


3.) Strange thing is the wscript.echo command echo’s the correct information. (wscript.echo longname)

"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" \\MyServer\Projects\RecallRoster_User\Application\Recallroster.mde /wrkgrp "\\MyServer\Projects\RecallRoster_User\Application\SecureRecall.mdw" /x "command-line"

4.) Source code

Call to Subroutine

If MemberOf(ObjGroupDict, "EW.script") Then
'If MemberOf(ObjGroupDict, "EW.RECALLROSTER USER") Then
' call addshortcuttodesktop("Short Cut Name", "Application Target Path", "start in folder")
longname = (chr(34) & "C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" & chr(34) & " " & "\\MyServer\Projects\RecallRoster_User\Application\Recallroster.mde" & " " & chr(47) & "wrkgrp" & " " & chr(34) & "\\MyServer\Projects\RecallRoster_User\Application\SecureRecall.mdw" & chr(34) & " " & chr(47) & "x" & " " & chr(34) & "command-line" & chr(34))
wscript.echo longname
Call addshortcuttodesktop("Recall Roster 2004", longname, "\\MyServer\Projects\RecallRoster_User\Application")
If testmode Then
wscript.echo "Member of EW.APP USER"
End If
End If

Subroutine

'************************************************************************************************************************
' call addshortcuttodesktop("Short Cut Name", "Application Target Path", "start in folder")
' call addshortcuttodesktop("APP", "\\MyServer\netapps\Program Files\APP\TAA\TAMAIN.EXE", "\\MyServer\netapps\Program Files\APP\TAA")
'
Sub addshortcuttodesktop(tname,tpath,tdir)
If testmode Then
wscript.echo "************ Subroutine addshortcuttodesktop *****************************************************************"
wscript.echo "Adding Short Cut : " & tname & ".lnk To users desktop"
wscript.echo "Target Path : " & tpath
wscript.echo "Working Directory : " & tdir
End If

Set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
Set oShellLink = WshShell.CreateShortcut(strDesktop & "\" & tname & ".lnk")
oShellLink.TargetPath = tpath
oShellLink.WindowStyle = 1
oShellLink.Description = tname & " Shortcut"
oShellLink.WorkingDirectory = tdir
oShellLink.Save
End Sub

 
Hello conan3,

Per documentation:
<quote>
object.CreateShortcut(strPathname)
Arguments
object
WshShell object.
strPathname
String value indicating the pathname of the shortcut to create.
...
Note A common problem is putting arguments in the TargetPath property of the shortcut object, which doesn't work. All arguments to the shortcut must be put in the Arguments property.
</quote>

I think you can then figure out what to do.
Code:
oShellLink.TargetPath =chr(34) & &quot;C:\Program Files\Microsoft Office\Office\MSACCESS.EXE&quot; & chr(34)
oShellLink.Arguments = &quot;\\MyServer\Projects\RecallRoster_User\Application\Recallroster.mde&quot; & &quot; &quot; & chr(47) & &quot;wrkgrp&quot; & &quot; &quot; & chr(34) & &quot;\\MyServer\Projects\RecallRoster_User\Application\SecureRecall.mdw&quot; & chr(34) &  &quot; &quot; & chr(47) & &quot;x&quot; & &quot; &quot; & chr(34) & &quot;command-line&quot; & chr(34)
I just cut-and-paste. You can sure make it back to your script by modifying the function adding a parameter.

regards - tsuji
 
Command arguments on a shortcut are set via the Arguments property. Maybe that's all that has gone wrong here.
 
To create a shortcut you have to split the command line into 2 things:
1) TargetPath
2) Arguments
i.e. something like this:
oShellLink.TargetPath=&quot;C:\Program Files\Microsoft Office\Office\MSACCESS.EXE&quot;
oShellLink.Arguments=Arguments with proper Chr(34) stuff

Hope This Help
PH.
 
Here is what I use and it came from a forum member. It works fine.

I also discovered that if you have switches with several
args, you can break these up in the same manner.

Try this...

MyShortCut.TargetPath = &quot;c:\notes\notes.exe&quot;
MyShortCut.Arguments = &quot;=m:\notes\data\notes.ini&quot; & &quot; &quot; etc..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top