?
Solved

Script to create application link on desktop

Posted on 2014-03-19
4
Medium Priority
?
673 Views
Last Modified: 2014-03-24
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

0
Comment
Question by:Bianca
  • 3
4 Comments
 
LVL 11

Assisted Solution

by:itguy565
itguy565 earned 2000 total points
ID: 39940136
This should help:

http://support.microsoft.com/kb/244677

WshShell = CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
oMyShortCut= WshShell.CreateShortcut(strDesktop+"\Foxtest.lnk")
oMyShortCut.WindowStyle = 7  &&Minimized 0=Maximized  4=Normal 
oMyShortcut.IconLocation = home()+"wizards\graphics\builder.ico"
oMyShortCut.TargetPath = "c:\Program Files\Microsoft Visual Studio\VFP98\vfp6.exe" 
oMyShortCut.Arguments = '-c'+'"'+Home()+'config.fpw'+'"'
oMyShortCut.WorkingDirectory = "c:\"
oMyShortCut.Save

Open in new window

0
 

Accepted Solution

by:
Bianca earned 0 total points
ID: 39940223
Thank you itguy565,

I didn't bother with the code listed but one key point in the code provided did give me a clue and it was a "duh" moment... "Argument"!  I added this string and objectlink to my code and BINGO... it works. Thanks for steering me in the right direction.
0
 

Author Comment

by:Bianca
ID: 39940243
thank you
0
 

Author Closing Comment

by:Bianca
ID: 39949816
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
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will learn how to implement Singleton Design Pattern in Java.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses
Course of the Month16 days, 18 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question