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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • UML图画法_画用例图的步骤

    UML图画法_画用例图的步骤一.用例图的作用用例图主要用来描述“用户、需求、系统功能单元”之间的关系。它展示了一个外部用户能够观察到的系统功能模型图。【用途】:帮助开发团队以一种可视化的方式理解系统的功能需求。二.用例图包含的元素 1.参与者(Actor)  表示与您的应用程序或系统进行交互的用户、组织或外部系统。用一个小…

    2022年9月7日
    0
  • 展频技术是如何搞定时钟信号的辐射的呢_辐射电磁波的频率

    展频技术是如何搞定时钟信号的辐射的呢_辐射电磁波的频率先前我们说了说:为什么时钟信号比数据信号更容易引起辐射超标?为什么时钟信号比数据信号更容易引起辐射超标?并且做了试验,如果认真看过的话,就会明白,周期性的信号是窄带频谱,特定的频率的幅值会很高,这对认证测试来说非常的不利。而一般时钟信号都是周期信号,这在电路中是少不了的。有没有什么办法,改造下时钟的频谱,同时又不影响功能呢?答案是有的,那就是展频技术。展频技术的应用展频技术经常用于解决辐射问题,比如我们前面说的音频功放,需要接LC滤波器。就有的厂家通过展频技术,推出不需要LC滤波器.

    2025年7月25日
    0
  • 栈和队列讲解_栈和队列的优缺点

    栈和队列讲解_栈和队列的优缺点目录1、栈(1)栈的概念及结构(2)栈的实现2、队列(1)队列的概念及结构(2)队列的实现前言:栈和队列是在顺序表和链表的延伸,如果前面的顺序表和链表你已经掌握了的话,栈和队列对你来说应该就是小菜一碟了。1、栈(1)栈的概念及结构栈:一种特殊的线性表,其只允许在固定的一端进行插入和删除元素操作。进行数据插入和删除操作的一端称为栈顶,另一端称为栈底。栈中的数据元素遵守后进先出LIFO(LastInFirstOut)的原则。压栈:栈的插入操作叫做进栈/压栈..

    2025年6月22日
    1
  • Lambda架构简介

    Lambda架构简介参考文章:深入理解大数据架构之——Lambda架构传统系统的问题“我们正在从IT时代走向DT时代(数据时代)。IT和DT之间,不仅仅是技术的变革,更是思想意识的变革,IT主要是为自我服务,用来更好地自我控制和管理,DT则是激活生产力,让别人活得比你好”——阿里巴巴董事局主席马云。数据量从M的级别到G的级别到现在T的级、P的级别。数据量的变化数据管理系统(DBMS)和数仓系统(DW)也在悄然的变化着。传统应用的数据系统架构设计时,应用直接访问数据库系统。当用户访问量增加时,数据库无法支撑

    2022年6月25日
    31
  • kindeditor自定义上传文件的路径[通俗易懂]

    kindeditor自定义上传文件的路径[通俗易懂]先上一张图这个项目是tp5.0做的,网站定义入口文件在public下,所以根目录下就是hook,static,upload三个文件夹。找到upload_json.php修改文件保存路径和保存目录就ok了;不骗你,再来张。…

    2022年9月13日
    0
  • JAVA | StringUtils中 isNotEmpty 和 isNotBlank的区别[通俗易懂]

    JAVA | StringUtils中 isNotEmpty 和 isNotBlank的区别[通俗易懂]isNotEmpty和isNotBlank的区别

    2022年8月12日
    9

发表回复

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

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