Results 1 to 21 of 21

Thread: [RESOLVED] Creating short-cuts

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    33

    Resolved [RESOLVED] Creating short-cuts

    I was wondering how i can write a program to create a shortcut in the startup folder of a different program. So i have one program on my computer that should run at startup, i just need another program to create a shortcut to it, and then copy this shortcut into the startup folder. Thanks

  2. #2
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: Creating short-cuts

    Google "vb.net create shortcut"
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Creating short-cuts

    Creating shortcuts in VB.NET is not simple and requires unmanaged code, i.e. referencing a Windows COM library. If it's not inappropriate, it's far easier to add a Registry entry to the Run key to run your app at startup. It makes it harder, although far from impossible, for the user to edit or delete it, which may be a good thing or a bad thing, depending on the circumstances.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: Creating short-cuts

    jmc has a good point, you should probably stick to the registry if its just for startup.

    But also to prove my point about googling things, very first link.
    http://www.tek-tips.com/faqs.cfm?fid=6127
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    33

    Thumbs up Re: Creating short-cuts

    Yeah I tried the code from the google link
    i have heaps of errors. Firstly the bit at the top -
    Code:
    Imports IWshRuntimeLibrary
    has green underline and says - "Namespace or type specified in the Imports 'IWshRuntimeLibrary' doesnt contain any public member or cannot be found.

    And there are blue lines underneath wShell and IWshRuntimeLibrary.IWshShortcut
    Here is the code

    Code:
    Imports IWshRuntimeLibrary
    Code:
    Private 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
            IO.Directory.CreateDirectory(creationDir)
          Else
            Return False
          End If
        End If
    
        Dim shortCut As IWshRuntimeLibrary.IWshShortcut
        shortCut = CType(wShell.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

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Creating short-cuts

    Did you read that page and perform the steps that it specifies, particularly steps 2 and 3, or did you just copy and paste the code?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    33

    Thumbs up Re: Creating short-cuts

    Copy and Paste

    Most is good but there is still this error - "Name wShell is not declared"

    in this bit of code -

    Code:
    shortCut = CType(wShell.CreateShortcut(creationDir & "\" & shortcutName & ".lnk"),

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Creating short-cuts

    If you don't follow instructions then it's isn't really surprising it didn't work. That said, it should be noted that the COM component you need to reference is named "Windows Script Host Object Model". Also, it looks like the wShell variable used in that code has not been declared. It should be type IWshShell3.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    33

    Thumbs up Re: Creating short-cuts

    Quote Originally Posted by jmcilhinney View Post
    If you don't follow instructions then it's isn't really surprising it didn't work. That said, it should be noted that the COM component you need to reference is named "Windows Script Host Object Model". Also, it looks like the wShell variable used in that code has not been declared. It should be type IWshShell3.
    So how do i make the type IwshShell3?

  10. #10
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Creating short-cuts

    Add the reference. Did you do that?

    Just use Dim var As IWshShell3, as usual. (With the Import, of course.)

  11. #11

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    33

    Thumbs up Re: Creating short-cuts

    So what should my code look like?
    could you post an example?
    Sorry, i am just a beginner

  12. #12
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: Creating short-cuts

    Your code should look just like that in the example. You just need to go back and add all of the correct references. I would suggest making a new project and going through every step in that link again, this time don't just copy and paste code.
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  13. #13

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    33

    Thumbs up Re: Creating short-cuts

    Ok i've done that and it still has the same error. "Name 'wShell' is not declared."

  14. #14
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Creating short-cuts

    So declare it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  15. #15

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    33

    Thumbs up Re: Creating short-cuts

    HOW?
    Im a noob at this
    I taught myself vb, and missed most basics

  16. #16
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Talking Re: Creating short-cuts

    The extremely complicated and advanced piece of code you will need is "Dim".

    Add a variable declaration of wShell as type IWshShell3 in your code (class-level).

  17. #17

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    33

    Re: Creating short-cuts

    MY GOD how complex
    thanks its fine now

  18. #18
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Creating short-cuts

    Quote Originally Posted by TysonJ33T View Post
    I taught myself vb, and missed most basics
    Being self-taught doesn't mean you have to have missed out on the basics. I strongly suggest that you find yourself a beginners tutorial and work through it so that you cover those fundamental concepts that you may currently be missing.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  19. #19
    Fanatic Member
    Join Date
    Aug 2003
    Location
    ohio, usa
    Posts
    719

    Re: Creating short-cuts

    Quote Originally Posted by TysonJ33T View Post
    MY GOD how complex
    thanks its fine now
    it is not clear how you actually solved the issue of adding the reference.

    I added the scripting reference but the Imports still gives me an error.

  20. #20
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: [RESOLVED] Creating short-cuts

    Project > Add Reference is how you did it, right?

  21. #21
    Fanatic Member
    Join Date
    Aug 2003
    Location
    ohio, usa
    Posts
    719

    Re: [RESOLVED] Creating short-cuts

    Quote Originally Posted by minitech View Post
    Project > Add Reference is how you did it, right?
    the only place to add it is in the project properties?

    I only found it there.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width