Solved

Create an application shortcut using VB.NET code

Posted on 2009-03-30
3
556 Views
Last Modified: 2012-08-13
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

0
Comment
Question by:darcher23
  • 2
3 Comments
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 24018267
try setting .arguments instead of passing it into target path

eg

    Public Function CreateShortCut(ByVal strName As String, _
                                    ByVal strTargetDirectory As String, _
                                    ByVal strTargetPath As String, _
                                    ByVal strArguments 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
            .Arguments = strArguments
            .WorkingDirectory = strWorkingDir
            .IconLocation = strIconFile
            .WindowStyle = 1
            .Description = "Ripteq Automation Task for Batch: " & strBatch
            .Save()

        End With

    End Function



So now pass in C:\Users\fredsmith\Projects\HelloWorls\bin\Debug\HellowWorld.exe in the target path as 3 MAP as arguments


0
 

Author Comment

by:darcher23
ID: 24028386
Thanks rockiroads .... Works like a charm!
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24028473
Cool :)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now