Hallo, ich habe es gerade mal getestet, es funktioniert auch mit Ordnern.
Aufruf:
Private Sub Command1_Click()
CreateLink "D:\Bilder", _
GetSpecialFolder(sfidDESKTOP) & "\Bilder.lnk"
' gleicher Link - anderer Pfad
CreateLink "D:\Daten", _
GetSpecialFolder(sfidDESKTOP) & "\Bilder.lnk"
End Sub In Modul:
Option Explicit
Public Enum SpecialFolderIDs
sfidDESKTOP = &H0
sfidPROGRAMS = &H2
sfidPERSONAL = &H5
sfidFAVORITES = &H6
sfidSTARTUP = &H7
sfidRECENT = &H8
sfidSENDTO = &H9
sfidSTARTMENU = &HB
sfidDESKTOPDIRECTORY = &H10
sfidNETHOOD = &H13
sfidFONTS = &H14
sfidTEMPLATES = &H15
sfidCOMMON_STARTMENU = &H16
sfidCOMMON_PROGRAMS = &H17
sfidCOMMON_STARTUP = &H18
sfidCOMMON_DESKTOPDIRECTORY = &H19
sfidAPPDATA = &H1A
sfidPRINTHOOD = &H1B
sfidProgramFiles = &H10000
sfidCommonFiles = &H10001
End Enum
Private Type SHITEMID
cb As Long
abID As Byte
End Type
Private Type ITEMIDLIST
mkid As SHITEMID
End Type
Private Declare Function SHGetSpecialFolderLocation Lib _
"shell32.dll" (ByVal hwndOwner As Long, _
ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
Private Declare Function SHGetPathFromIDList Lib _
"shell32.dll" Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, ByVal pszPath As String) As Long
Public Sub CreateLink(ByVal Datei As String, _
ByVal LinkName As String, _
Optional ByVal Parameter As String = "", _
Optional ByVal Comment As String = "", _
Optional ByVal WorkingDir As String = "")
Dim cShellLink As ShellLinkA
Dim cPersistFile As IPersistFile
Set cShellLink = New ShellLinkA
Set cPersistFile = cShellLink
With cShellLink
' Pfad+Dateiname der Anwendung
.SetPath Datei
' Parameter
If Parameter <> "" Then _
.SetArguments Parameter
' Kommentar
If Comment <> "" Then _
.SetDescription Comment
' Arbeitsverzeichnis (Ausführen in)
If WorkingDir <> "" Then _
.SetWorkingDirectory WorkingDir
End With
' Verknüpfung erstellen
cPersistFile.Save StrConv(LinkName, _
vbUnicode), 0
Set cPersistFile = Nothing
Set cShellLink = Nothing
End Sub
Public Function GetSpecialFolder(CSIDL As _
SpecialFolderIDs) As String
Dim lResult As Long
Dim IDL As ITEMIDLIST
Dim sPath As String
lResult = SHGetSpecialFolderLocation(100, CSIDL, IDL)
If lResult = 0 Then
sPath = Space$(512)
lResult = SHGetPathFromIDList(ByVal IDL.mkid.cb, _
ByVal sPath)
GetSpecialFolder = Left$(sPath, InStr(sPath, _
Chr$(0)) - 1)
End If
End Function |