Note this code will ignore duplicate shortcuts. For example I have 4 or 5 shortcuts in my Start Menu that are named "Readme.txt." Only the first instance of these will get added to the commands all others will produce an error and will be Ignored.
Add The Following Objects to your project:
Object Type Object Name New Module Doesn't Matter New FormMain Function Submain () - The Project Will Need To Start Up Here. Microsoft Agent Control Agent
Add The Following to a New Code Module: Option Explicit
Public Declare Function ShellExecute Lib "shell32.dll" _ Alias "ShellExecuteA" _ (ByVal hwnd As Long, _ ByVal lpOperation As String, _ ByVal lpFile As String, _ ByVal lpParameters As String, _ ByVal lpDirectory As String, _ ByVal nShowCmd As Long) As long
Public a as IAgentctlcharacTerpublic Request as Objectpublic Fso As New FileSystemObject
Public Type Shortcut Name As String * 80 Path AS String * 150nd Type
Public shortcuts () AS Shortcut
Sub main () loading.folder dimr as scripting.Folder Dim Wfldr as scripting.folder redim shriTCUTS (0) '******************************************** ********************** 'Use default character by not including the path' ************************* ***************************************** FRMMAIN.AGENT.CHARACTERS.LOAD "Agent" set a = frmmain.agent.characters ("Agent") '************************************************** **************************************************************************************************************************************TION ************** SET WFLDR = fso.getspecialfolder (windowsfolder) '******************************************* **************************************************************************************************** ************************************ SET FLDR = fso.getFolder (Wfldr.Path & "/ Start Menu) Call AddFolderCommands (FLDR, "* .lnk") '************************************************************* ****** 'GET Desktop shortcuts' ******************************************************************************************************************************* ********** SET FLDR = fso.getfolder (wfldr.path & "/ sta RT MENU ") Call AddFolderCommands (FLDR," * .LNK ") '******************************************* ************** 'GET FAVORITES SHORTCUTS' ****************************************** ******************* SET FLDR = fso.getFolder (Wfldr.Path & "/ Start Menu") Call AddFolderCommands (FLDR, "* .url") A.Shownd Sub
Public Sub AddFolderCommands (rfldr As Scripting.Folder, _ lsFileMask As String) Dim f As Scripting.File Dim lsName As String Dim x As Long Dim fldr As Scripting.Folder If fso.FolderExists (rfldr.Path) Then '**** **************************************************************** 'CHECK EACH FILE TO SEE IF IT FITS THE MASK '**************************************************** ****** for Each F in rfldr.files if f.name like lsfilemask life x = instribrate, ".", Vbtextcompare) IF x <> 0 Then Lsname = TRIM $ (Left $ (f) .Name, x - 1) ELSE LSNAME = TRIM $ (F.NAME) Endiff Call Addcommand (Lsname, Trim $ (F.Path)) end if next '************ ******************************************** 'Do this for Each Sub Folder AS Well' **** *************************************************** For Each fldr In rfldr.SubFolders Call AddFolderCommands (fldr, lsFileMask) Next End IfEnd SubPublic Sub AddCommand (lsName As String, lsPath As String) On Error GoTo EndCmd '**************** ****************************************** The 'if the is duplicate items ignore all but the' first instance. '** ***************************************************************** A.Commands .. .Add lsName, lsName, lsName, True, True ReDim Preserve ShortCuts (UBound (ShortCuts) 1) ShortCuts (UBound (ShortCuts)) Name = lsName ShortCuts (UBound (ShortCuts)) Path = lsPathEndCmd:
End Sub