Solved

Create an application shortcut using VB.NET code

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

839 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