Solved

Create an application shortcut using VB.NET code

Posted on 2009-03-30
3
562 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

740 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