0

I am trying to make a shortcut for my program so that it starts automatically with windows. The following code is the sub that creates the shortcut and how it gets it's variables but it fails.

Dim ShortCutPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Startup) & "/ScreenRot.lnk"



Shared Sub CreateShortCut(File As String, ShortCutPath As String)

    Dim oShell As Object
    Dim oLink As Object
    'you don’t need to import anything in the project reference to create the Shell Object

    Try

        oShell = CreateObject("WScript.Shell")
        oLink = oShell.CreateShortcut(ShortCutPath)
        oLink.IconLocation = File
        oLink.TargetPath = File
        oLink.Arguments = ""
        oLink.WindowStyle = 1
        oLink.Save()

    Catch ex As Exception

    End Try

End Sub

The line it seems to fail on is.

oLink = oShell.CreateShortcut(ShortCutPath)

The error I am getting is

DirectCast(ex, System.MissingMemberException).Message Public member 'CreateShortcut' on type 'IWshShell3' not found.

I am using this in my program.

Imports IWshRuntimeLibrary

I have tried a couple different ways to make the shortcut but this seems to be the one that should work for what I need. I've read a bit about using this code and watched a video but nothing talks about the error. I've googled the error but nothing resembles a solution. I've tried to adjust the code slightly by using other examples but it still fails with more or less the same error. I don't really understand what the error is saying, so I can try and figure it out. thanks for your time and any help you guys can give.

  • Isn’t your slash the wrong way around when constructing the short cut path? Would be better off using Path.Combine() method in System.Io namespace – Hursey Jul 31 '22 at 18:00
  • thanks for your reply, I have tried with the slash the correct way round but it still fails at the same spot, will try your suggestion of Path.combine() – Alex McCreath Jul 31 '22 at 19:29
  • after trying the path combine suggested it still fails on the same command, i dont think the path is the problem, it seems to be more a problem with this error "Public member 'CreateShortcut' on type 'IWshShell3' not found." – Alex McCreath Aug 01 '22 at 19:36

1 Answers1

0

After reviewing many posts and trying a lot of different things I found a solution on Stackoverflow which I can confirm actually works. Stackoverflow Post

This post has the solution, hopefully it helps other people with this problem.