Using MSAgent to Scan the Start Menu 选择自 wm_ni 的 Blog

Using MSAgent to Scan the Start Menu 选择自 wm_ni 的 BlogNotethiscodewillignoreduplicateshortcuts.ForexampleIhave4or5shortcutsinmyStartMenuthatarenamed”Readme.txt.”Onlythefirstinstanceofthesewillgetaddedtothecommandsallot

大家好,又见面了,我是你们的朋友全栈君。

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 Form       frmMain
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 IAgentCtlCharacter
Public Request As Object
Public fso As New FileSystemObject

Public Type ShortCut
    Name As String * 80
    Path As String * 150
End Type

Public ShortCuts() As ShortCut

Sub Main()
    Load frmMain
    Dim fldr As Scripting.Folder
    Dim wfldr As Scripting.Folder
    ReDim ShortCuts(0)
   
    ‘*************************************************
    ‘Use default Character by not including the path
    ‘*************************************************
    frmMain.Agent.Characters.Load “Agent”
    Set a = frmMain.Agent.Characters(“Agent”)
       
    ‘*************************************************
    ‘Find out the path of the windows directory
    ‘*************************************************
    Set wfldr = fso.GetSpecialFolder(WindowsFolder)
   
    ‘*************************************************
    ‘Get Start Menu Shortcuts
    ‘*************************************************
    Set fldr = fso.GetFolder(wfldr.Path & “/Start Menu”)
    Call AddFolderCommands(fldr, “*.lnk”)
   
    ‘*************************************************
    ‘Get Desktop Shortcuts
    ‘*************************************************
    Set fldr = fso.GetFolder(wfldr.Path & “/Start Menu”)
    Call AddFolderCommands(fldr, “*.lnk”)
   
    ‘*************************************************
    ‘Get Favorites Shortcuts
    ‘*************************************************
    Set fldr = fso.GetFolder(wfldr.Path & “/Start Menu”)
    Call AddFolderCommands(fldr, “*.url”)
   
    a.Show
End 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 Then
                x = InStrRev(f.Name, “.”, , vbTextCompare)
                If x <> 0 Then
                    lsName = Trim$(Left$(f.Name, x – 1))
                Else
                    lsName = Trim$(f.Name)
                End If
               
                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 If
End Sub

Public Sub AddCommand(lsName As String, lsPath As String)
    On Error GoTo EndCmd
   
    ‘*************************************************
    ‘If there 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 = lsPath
EndCmd:

End Sub

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/151648.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 网管工具箱小程序_小管家使用教程

    网管工具箱小程序_小管家使用教程

    2022年9月27日
    2
  • BigDecimal 加减乘除运算[通俗易懂]

    加法add()函数BigDecimaln1=newBigDecimal(“0.01”);BigDecimaln2=newBigDecimal(“0.02”);System.out.println(“加法:”+n2.add(n1));加法:0.03减法subtract()函数BigDecimaln1=newBigDecimal(“0.01”);BigDecimaln2=newBigDecimal(“0.02”);System….

    2022年4月14日
    56
  • 重写和重载的区别是什么「建议收藏」

    重写和重载的区别是什么「建议收藏」重写和重载的区别是什么

    2025年10月10日
    2
  • SpringBoot与Spring的区别

    SpringBoot与Spring的区别SpringBoot不是Spring官方的框架模式,而是一个团队在Spring4.0版本上二次开发并开源公布出来的。简而言之,SpringBoot就是一个轻量级,简化配置和开发流程的web整合框架。SpringBoot是最近这几年才火起来的,那么它到底与Spring有啥区别呢?想了解区别,其实就是SpringBoot提供了哪些特性:SpringBoot可以建立独立的Spring应用程序; …

    2022年6月13日
    32
  • 【c语言】malloc函数详解[通俗易懂]

    【c语言】malloc函数详解[通俗易懂]谈到malloc函数相信学过c语言的人都很熟悉,但是malloc底层到底做了什么又有多少人知道。关于malloc相关的几个函数关于malloc我们进入Linuxman一下就会得到如下结果:也可以这样认为(window下)原型:externvoid*malloc(unsignedintnum_bytes);头文件:#include&amp;lt;malloc.h…

    2022年6月14日
    70
  • html5设计礼品盒效果,十大包装创意设计网站「建议收藏」

    html5设计礼品盒效果,十大包装创意设计网站「建议收藏」有时您只需要一些启发。好吧,这是10个包装创意设计网站,这些网站充满了新颖的样品和具有创意的图文信息!花一些时间筛选它们,我们确信您会充满活力,可以重新包装或开始为您的产品选择正确的方向。没有比看看其他人为解决商品销售而进行的创新设计。这10个包装设计网站将使您的创意源源不断:1.www.thedieline.com还为包装设计缺乏灵感来源烦恼吗?现在,此网站为包装创意设计的访问量最大的网站之一…

    2025年7月8日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号