tags:

views:

475

answers:

2
Imports IWshRuntimeLibrary
Module MainModule
    Public Function CreateShortCut(ByVal shortcutName As String, ByVal creationDir As String, ByVal targetFullpath As String, ByVal workingDir As String, ByVal iconFile As String, ByVal iconNumber As Integer) As Boolean
        Try
            If Not IO.Directory.Exists(creationDir) Then
                Dim retVal As DialogResult = MsgBox(creationdir & " does not exist. Do you wish to create it?", MsgBoxStyle.Question Or MsgBoxStyle.YesNo)
                If retVal = DialogResult.Yes Then
                    IO.Directory.CreateDirectory(creationDir)
                Else
                    Return False
                End If
            End If

            Dim shortCut As IWshRuntimeLibrary.IWshShortcut
            shortCut = CType(WshShell.CreateShortcut(creationDir & "\" & shortcutName & ".lnk"), IWshRuntimeLibrary.IWshShortcut)
            shortCut.TargetPath = targetFullpath
            shortCut.WindowStyle = 1
            shortCut.Description = shortcutName
            shortCut.WorkingDirectory = workingDir
            shortCut.IconLocation = iconFile & ", " & iconNumber
            shortCut.Save()
            Return True
        Catch ex As System.Exception
            Return False
        End Try
    End Function
+2  A: 

It means you're using an instance of a class to qualify one of its shared members instead of the class itself. For example:

Class C
    Public Shared x As Integer
End Class
Module M
    Sub S(instance as C)
        dim x1 = instance.X 'warning
        dim x2 = C.X 'proper
    End Sub
End Module
Strilanc
can you please explain how i would fix it
Alex Bridges
Which line are you getting the warning on?
Strilanc
Alex Bridges
I'd guess that WshShell is an instance of some class. Hover over it to see the type, and replace WshShell with the type.
Strilanc
well all i get when i hover over it is the error
Alex Bridges
Oh, right. Place the text cursor within it and hit ctrl+i.
Strilanc
it says "Interface wshShell" what does that mean? and btw thanks for the help i really apreciate it
Alex Bridges
Strilanc
tried that still got the same error... :\
Alex Bridges
Well, I'm afraid I can't really help more. It really looks like you have to figure out what type wshShell is and replace 'wshShell' with that type's name. If ctrl+i did not work, maybe 'Go to reference' from the context menu will.
Strilanc
Okay, thanks for trying to help.
Alex Bridges
A: 

You need to create an instance of WshShell, I think:

Dim NewWshShell As New WshShell

now use newWshShell in place of WshShell

MattYerbs