Solved

Create an application shortcut using VB.NET code

Posted on 2009-03-30
3
557 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get String split 5 46
Close word object 13 38
I need help embedding an image as HTML in my vb.net application 3 45
Put window Form inside tab page 10 26
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…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

10 Experts available now in Live!

Get 1:1 Help Now