Link to home
Start Free TrialLog in
Avatar of darcher23
darcher23

asked on

Create an application shortcut using VB.NET code

Hi Experts,

I have code using the Windows Scripting Host Object, to successfully create a desktop shortcut.  However, my problem is populating this shortcut with the correct startup parameters.

The string required in the TARGET field has 2 parameters - an integer, and a code.  I've found that when I create the shortcut, it encapsulates the entire File Path Integer Code in quotes, where as I need either each component in quotes, or no quotes at all (best).

eg.  C:\Users\fredsmith\Projects\HelloWorls\bin\Debug\HellowWorld.exe 3 MAP

Any suggestions out there?

Cheers,
David.
Public Function CreateShortCut(ByVal strName As String, ByVal strTargetDirectory As String, ByVal strTargetPath As String, ByVal strWorkingDir As String, ByVal strIconFile As String, ByVal strBatch As String) As clsResult
 
        Dim wshShell As New WshShell
        Dim desktop As String = My.Computer.FileSystem.SpecialDirectories.Desktop
        'Dim desktop As String = wshShell.SpecialFolders.Item("Desktop").ToString()
 
        Dim shortcut As IWshShortcut = CType(wshShell.CreateShortcut(desktop & "\" & strName.ToString & ".lnk"), IWshShortcut)
        With shortcut
            .TargetPath = strTargetPath.Replace(Chr(34), String.Empty)
            .WorkingDirectory = strWorkingDir
            .IconLocation = strIconFile
            .WindowStyle = 1
            .Description = "Ripteq Automation Task for Batch: " & strBatch
            .Save()
 
        End With
 
    End Function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of rockiroads
rockiroads
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
Avatar of darcher23
darcher23

ASKER

Thanks rockiroads .... Works like a charm!
Cool :)