?
Solved

Create an application shortcut using VB.NET code

Posted on 2009-03-30
3
Medium Priority
?
566 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 2000 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
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 …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

752 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