Results 1 to 7 of 7

Thread: Creating ShortCut

  1. #1

    Thread Starter
    Lively Member FireDust's Avatar
    Join Date
    Feb 2013
    Location
    Slovakia
    Posts
    112

    Question Creating ShortCut

    I just made an Sub called CreateShortcut and it should 100% work... And I even figured out the problem, but I have no idea how to fix it.

    Code:
    Code:
    Dim UserName As String = Environment.UserName
    Dim Path As String = "C:\Users\" & UserName & "\AppData\Roaming\AppHolder"
    Dim ShortcutDirectory As String = "C:\Users\" & UserName & "\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\"
    Dim OldPath As String = "C:\Users\" & UserName & "\AppData\Roaming\AppHolder\Updating\PathToProgram.txt"
    
     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim StreamReader As System.IO.StreamReader = New System.IO.StreamReader(OldPath)
            OldPath = StreamReader.ReadToEnd
    End Sub
    
    Private Sub CreateShortCut(ByVal FilePath As String)
            Try
                Dim Shortcut As IWshShortcut
                Dim Wsh As New WshShell
    
                Shortcut = CType(Wsh.CreateShortcut(ShortcutDirectory & "Application Holder.lnk"), IWshShortcut)
                With Shortcut
                    .TargetPath = FilePath
                    .Description = "Description?"
                    .IconLocation = FilePath & ", 0"
                    .Save()
                End With
    
            Catch Excep As Exception
                Debug.WriteLine(TimeString)
                Debug.WriteLine(Excep.Message)
                Stop
            End Try
        End Sub
    The path to File is in the text file that you saw me "Reading". The path in the text file is just simple "C:\Users\Marek\Desktop\Application Grid.exe". If I replace FilePath in CreateShortcut Sub, with this path, it works! Why it does this???

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    Re: Creating ShortCut

    What happens if you were to compile the app as ApplicationGrid.exe rather than Application Grid.exe ? Thinking the space may be the issue. It is against my better judgement to use a space in an application name so I can't say if this is it or not.

  3. #3

    Thread Starter
    Lively Member FireDust's Avatar
    Join Date
    Feb 2013
    Location
    Slovakia
    Posts
    112

    Re: Creating ShortCut

    Nope. Still does not work...

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Creating ShortCut

    Evidently what you get from the file is not what you think it is. I notice that you're using streamreader ReadToEnd so is it possible that there's a stray character at the end of the line (a carriage return or a space?) It's very easily checked. Just put in a line like ...

    If FilePath <> "C:\Users\Marek\Desktop\Application Grid.exe" Then MsgBox("See! Told you so!")
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Creating ShortCut

    I don't see you call the CreateShortCut sub anywhere in your code....
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  6. #6

    Thread Starter
    Lively Member FireDust's Avatar
    Join Date
    Feb 2013
    Location
    Slovakia
    Posts
    112

    Re: Creating ShortCut

    Ok.. I forgot to add at the forum :P
    Code:
    CreateShortCut(OldPath)
    And thanks dunfiddlin! I pressed Enter as I allways do when I finnish off typing, and I did not know that it takes ENTER space as character Thanks!

  7. #7

    Thread Starter
    Lively Member FireDust's Avatar
    Join Date
    Feb 2013
    Location
    Slovakia
    Posts
    112

    Re: Creating ShortCut

    Thats ok, It was my typing fault... :P

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