Help creating shortcut with arguements

Lashway, Ryan 20 Reputation points
2024-09-25T13:31:59.1766667+00:00

I have a process that creates shortcuts for startup and desktop for individual or all users.

In this I app I am trying to create a shortcut with arguments.

The section of my code I am having an issue with is below:

Dim program_path as string = "C:\Program Files (x86)\Wonderware\InTouch\view.exe"

Dim application_path as string = "C:\Users\Public\Wonderware\InTouch Applications\code_to_use.dev"

desktopshortcut.targetpath = program_path

desktopshortcut.workingdirectory = "C:\Program Files (x86)\Wonderware\InTouch"

desktopshortcut.Save()

What I need to do is create a shortcut that has a targetpath = "C:\Program Files (x86)\Wonderware\InTouch\view.exe" "C:\Users\Public\Wonderware\InTouch Applications\code_to_use.dev"

Issue is, I can not get the "" to show up, as I need those for the target path, if I use something like Dim full_path as string = program_path + " " +applicatin_path it trims out the " " in the middle and errors.

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,722 questions
{count} votes

Accepted answer
  1. Castorix31 84,956 Reputation points
    2024-09-25T13:57:25.2266667+00:00

    This test with Notepad works for me :

    (I replaced TargetPath with a .exe with spaces in the path and it worked...)

                ' Add reference to Windows Script Host Object Model
                ' Add Imports IWshRuntimeLibrary
                Dim shell As New WshShell()
                Dim sDesktopPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
                Dim sShortcutPath As String = Path.Combine(sDesktopPath, "NotepadShortcut.lnk")
                Dim shortcut As IWshShortcut = CType(shell.CreateShortcut(sShortcutPath), IWshShortcut)
                shortcut.TargetPath = """C:\Windows\System32\notepad.exe"""
                shortcut.Arguments = """e:\Test file.txt"""
                shortcut.WorkingDirectory = "C:\Windows\System32"
                shortcut.IconLocation = "C:\Windows\System32\notepad.exe, 0"
                shortcut.Save()
    
    

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.