-
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???
-
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.
-
Re: Creating ShortCut
Nope. Still does not work...
-
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!")
-
Re: Creating ShortCut
I don't see you call the CreateShortCut sub anywhere in your code....
-
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 :D Thanks!
-
Re: Creating ShortCut
Thats ok, It was my typing fault... :P