Advertisement
7_2009-2012 Windows System Services #221304

create a Shelllink (also known as Shortcut) with a few lines of code

It creates a shortcut and lets you define all important parameters. I have seen some examples before, but they where all too complicated for this little job. So I collected informationen and wrote this.

AI

Resumo por IA: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Código fonte
original-source
Option Explicit
Enum Windowstyle
  Minimized = 7
  Maximized = 3
  Normal = 1
End Enum
Public Function CreateShortcut(Linkpath As String, TargetPath As String, Optional WorkPath As String, Optional HotKey As String = "", Optional Description As String = "", Optional Winstyle As Windowstyle, Optional Iconnumber As Integer)
  Dim SC As Object
  Set SC = CreateObject("Wscript.Shell").CreateShortcut(Linkpath)
  
  With SC
    .TargetPath = TargetPath
    'where your shortcuts jumps to
    
    .HotKey = HotKey
    'can be "CTRL+SHIFT+E" (as Str!) for Example
    
    .Description = Description
    'this should be clear to you
    
    .Windowstyle = Winstyle
    'Winstyle differs from the typical styles (2 does not mean maximized)
    
    .IconLocation = TargetPath & ", " & Iconnumber
    'This will take the Icon for the link from the file its associated with (targetpath)
    'some files include more than one icon. This is what is meant by Iconnumber.
    
    .WorkingDirectory = WorkPath
    'The normal Workingdirectory for the file the link calls.
    
    .Save
    'saves the link [important! :-)]
  End With
End Function
Comentários originais (3)
Recuperado do Wayback Machine