...mi sa che ho scritto una fesseria.
allora:
credo di essermi sbagliato nel titolo. Credo che WMI non c'entri nulla.
La questione non è WMI o API, ma OBJECT o API.
Nel senso che per creare una icona nella barra di avvio veloce in basso (credo si chiami Quick launch bar) ho trovato questo codice:
codice:
Const APPLICATION_DATA = &H1a&
Dim MyShortcut
Dim QuickLaunchPath
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(APPLICATION_DATA)
Set objFolderItem = objFolder.Self
On Error resume next
Set WSHShell = CreateObject("WScript.Shell")
If not WSHShell Is Nothing Then
QuickLaunchPath = objFolderItem.Path & "\Microsoft\Internet Explorer\Quick Launch"
Set MyShortcut = WSHShell.CreateShortCut(QuickLaunchPath & "\MyApp.lnk")
MyShortcut.TargetPath = "c:\MyPath\MyApp.exe"
MyShortcut.WorkingDirectory = "c:\MyPath"
MyShortcut.WindowStyle = 1
MyShortcut.Arguments = ""
MyShortcut.IconLocation = "c:\MyPath\MyApp.exe,0"
MyShortcut.Save
Set MyShortcut = Nothing
end if
mentre da un'altra parte ho trovato questo cosice:
codice:
Option Explicit
Private Declare Function VB4CreateShellLink Lib "STKIT432.DLL" Alias "fCreateShellLink" (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal lpstrLinkPath As String, ByVal lpstrLinkArgs As String) As Long
Private Declare Function VB5CreateShellLink Lib "VB5STKIT.DLL" Alias "fCreateShellLink" (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal lpstrLinkPath As String, ByVal lpstrLinkArgs As String) As Long
Private Declare Function VB6CreateShellLink Lib "VB6STKIT.DLL" Alias "fCreateShellLink" (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal lpstrLinkPath As String, ByVal lpstrLinkArgs As String, ByVal fPrivate As Long, ByVal sParent As String) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Enum VersioneVB
VisualBasicUnknown = 0
VisualBasic4 = 4
VisualBasic5 = 5
VisualBasic6 = 6
End Enum
Private AppPath As String
Private Function CreateShellLink(ByVal intVersione As VersioneVB, ByVal strGruppo As String, ByVal strTitolo As String, ByVal strPath As String) As Boolean
Dim intConta As Integer
Dim lngRis As Long
On Error GoTo Err_Handler
If intVersione = VisualBasicUnknown Then
For intConta = 4 To 6
lngRis = LoadLibrary(Choose(intConta - 3, "STKIT432", "VB5STKIT", "VB6STKIT"))
Call FreeLibrary(lngRis)
If lngRis <> 0 Then intVersione = intConta
Next intConta
End If
lngRis = 0
If intVersione = VisualBasic6 Then
lngRis = VB6CreateShellLink(strGruppo, strTitolo, strPath, "", True, "$(Programs)")
ElseIf intVersione = VisualBasic5 Then
lngRis = VB5CreateShellLink(strGruppo, strTitolo, strPath, "")
ElseIf intVersione = VisualBasic4 Then
lngRis = VB4CreateShellLink(strGruppo, strTitolo, strPath, "")
End If
CreateShellLink = CBool(lngRis)
Exit Function
Err_Handler:
CreateShellLink = False
End Function
Private Sub Form_Load()
AppPath = App.Path
If Right$(AppPath, 1) <> "\" Then AppPath = AppPath & "\"
AppPath = AppPath & App.EXEName & ".exe"
txtTitoloCollegamento.Text = App.Title
End Sub
Private Sub cmdCollegamentoMenuAvvio_Click()
Call CreateShellLink(VisualBasicUnknown, ".", txtTitoloCollegamento.Text, AppPath)
End Sub
Private Sub cmdCollegamentoDesktop_Click()
Call CreateShellLink(VisualBasicUnknown, "..\..\Desktop", txtTitoloCollegamento.Text, AppPath)
End Sub
che crea collegamento sul desktop e nella barra di avvio a sinistra.
La mia questione era: come faccio a fondere le due, visto che una usa le api, l'altra un altro sistema?
Ppotrei mettere la prima routine in un modulo insieme alle routine del metodo con le api, ma mi sembra brutto.