Link to home
Start Free TrialLog in
Avatar of Norm-al
Norm-alFlag for United States of America

asked on

Script to create application link on desktop

I have pulled out what stubble I have as hair trying to figure this.  I have some code that deletes an old desktop link and creates a new one however, the link I want created has in it's target a command and switch.  Normal creation this works fine, script it and the quotes that are required are passed. Adding code to eliminate quotes results in no space between application executable and switch, add code to inject a space in ANY format results in the preceding and ending quotes showing up again... clues?

Code as follows:

'begin shortcut creation function
strWorkDir ="C:\Directory" 
strAppPath = "c:\Directory\File.exe dbserver=server\instance"
strIconPath ="C:\Directory\File.exe"
'
Set objShell = CreateObject("WScript.Shell") 
objDesktop = objShell.SpecialFolders("Desktop")
Set objLink = objShell.CreateShortcut(objDesktop & "\File.lnk")
'
objLink.Description = "File"  
objLink.IconLocation = strIconPath  
objLink.TargetPath = strAppPath
objLink.WindowStyle = 3 
objLink.WorkingDirectory = strWorkDir 
objLink.Save
'end function

Open in new window

SOLUTION
Avatar of ITguy565
ITguy565
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Norm-al

ASKER

thank you
Avatar of Norm-al

ASKER

Thank you itguy565, this is how the code played out in the end:

Code as follows:

'begin shortcut creation function
strWorkDir ="C:\Directory"
strAppPath = "c:\Directory\File.exe"
strArgument =  "dbserver=server\instance"
strIconPath ="C:\Directory\File.exe"
'
Set objShell = CreateObject("WScript.Shell")
objDesktop = objShell.SpecialFolders("Desktop")
Set objLink = objShell.CreateShortcut(objDesktop & "\File.lnk")
'
objLink.Description = "File"  
objLink.IconLocation = strIconPath  
objLink.TargetPath = strAppPath
objLink.Argument = strArgument
objLink.WindowStyle = 3
objLink.WorkingDirectory = strWorkDir
objLink.Save
'end function