Desktop Shortcut wird teilweise mehrmals angelegt
-
Montag, 11. Februar 2013 14:23
Hi, ich lege mit folgenden Code einen Desktopshortcut an. Nur kommt es bei manchen Benutzern meines Programmes vor, das das Icon mehrfach angelegt wird, dafür habe ich so keine Erklärung. Könnt ihr mir weiterhelfen?
Call Create_Shortcut(Application.ExecutablePath, Environment.GetFolderPath(0), _ IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath), Application.StartupPath, "", 0, 0) Public Function Create_Shortcut(ByVal Target_Path As String, ByVal Shortcut_Path As String, ByVal Shortcut_Name As String, _ ByVal Working_Directory As String, ByVal Arguments As String, ByVal Window_Style As Integer, ByVal Icon_Num As Integer) As Object Try Dim objectValue As Object = RuntimeHelpers.GetObjectValue(Interaction.CreateObject("WScript.Shell", "")) Dim objectValue2 As Object = RuntimeHelpers.GetObjectValue(NewLateBinding.LateGet(objectValue, Nothing, _ "CreateShortcut", New Object() {Shortcut_Path & "\" & Shortcut_Name & ".lnk"}, Nothing, Nothing, Nothing)) NewLateBinding.LateSet(objectValue2, Nothing, "TargetPath", New Object() {Target_Path}, Nothing, Nothing) NewLateBinding.LateSet(objectValue2, Nothing, "WorkingDirectory", New Object() {Working_Directory}, Nothing, Nothing) NewLateBinding.LateSet(objectValue2, Nothing, "Arguments", New Object() {Arguments}, Nothing, Nothing) NewLateBinding.LateSet(objectValue2, Nothing, "WindowStyle", New Object() {Window_Style}, Nothing, Nothing) NewLateBinding.LateSet(objectValue2, Nothing, "IconLocation", New Object() {Target_Path & "," _ & Conversions.ToString(Icon_Num)}, Nothing, Nothing) NewLateBinding.LateCall(objectValue2, Nothing, "Save", New Object() {}, Nothing, Nothing, Nothing, True) Return True Catch ex As Exception End Try End Function
- Bearbeitet Ionut DumaMicrosoft Contingent Staff, Moderator Dienstag, 12. Februar 2013 15:26 Formatierung
Alle Antworten
-
Dienstag, 12. Februar 2013 15:30Moderator
Hallo Michael,
Kannst Du dass versuchen?
Dim wsh As Object = CreateObject("WScript.Shell") wsh = CreateObject("WScript.Shell") Dim MyShortcut, DesktopPath ' Read desktop path using WshSpecialFolders object DesktopPath = wsh.SpecialFolders("Desktop") ' Create a shortcut object on the desktop MyShortcut = wsh.CreateShortcut(DesktopPath & "\name of shortcut.lnk") ' Set shortcut object properties and save it MyShortcut.TargetPath = wsh.ExpandEnvironmentStrings("path to exe including the exe") MyShortcut.WorkingDirectory = wsh.ExpandEnvironmentStrings("path to exe without the exe") MyShortcut.WindowStyle = 4 'Use this next line to assign a icon other then the default icon for the exe 'MyShortcut.IconLocation = WSHShell.ExpandEnvironmentStrings("path to a file with an embeded icon", icon index number) 'Save the shortcut MyShortcut.Save()Gruss,
Ionut

