|
|
Exemples d'automation Shell
1- Récupérer la liste des chemins des raccourcis du bureau avec le nom du
raccourci.
Private Sub Liste1_GotFocus() Placer ce code dans le formulaire ou dans un module standard: Dim oShell As Object
Dim oShellSpace As Object
Dim oItem As Object
Public Function allShortCut() As String
On Error Resume Next
Set oShell = CreateObject("Shell.Application")
Set oShellSpace = oShell.NameSpace("C:\Documents and Settings\" & _
Environ$("username") & "\Bureau")
For Each oItem In oShellSpace.Items
If oItem.islink Then
allShortCut = allShortCut & oItem.Name & ";" & oItem.GetLink.path & ";"
End If
Next
Set oShell = Nothing
Set oShellSpace = Nothing
Set oItem = Nothing
End Function
Attention: cette fonction ne retourne un chemin que pour les raccourcis
concernant le nom d'utilisateur du login windows. Tout raccourci, référencé sous
l'utilisateur AllUsers est ignoré.
2- Récupérer le chemin d'un raccourci du bureau.
Private Sub Commande1_Click() Placer ce code dans le formulaire ou dans un module standard: Dim oShell As Object
Dim oShellSpace As Object
Dim oItem As Object
Public Function singleShortCut(strName As String) As String
On Error Resume Next
Set oShell = CreateObject("Shell.Application")
Set oShellSpace = oShell.NameSpace("C:\Documents and Settings\" & _
Environ$("username") & "\Bureau")
For Each oItem In oShellSpace.Items
If oItem.Name = strName Then
singleShortCut = oItem.GetLink.path
GoTo Exit_singleShortCut
End If
Next
singleShortCut = ""
Exit_singleShortCut:
Set oShell = Nothing
Set oShellSpace = Nothing
Set oItem = Nothing
End Function
Si le raccourci n'est pas trouvé, une chaîne vide est retournée.
Attention: cette fonction ne retourne un chemin que pour un raccourci concernant
le nom d'utilisateur du login windows. Tout raccourci, référencé sous
l'utilisateur AllUsers est ignoré. |
|