【问题标题】:How do you get the 'Target type' of a shortcut如何获得快捷方式的“目标类型”
【发布时间】:2013-09-13 11:05:00
【问题描述】:

我想删除桌面文件夹中的所有快捷方式,并确保添加了一组干净的快捷方式。

但是,我需要保留映射驱动器的快捷方式。如果您查看“属性”的“快捷方式”选项卡,您可以看到这种类型的快捷方式具有“文件夹”的Target type

问题是,我找不到任何通过 VBS 访问目标类型的方法。我可以获取类型 (objFile.Type),但它会在“常规”选项卡上为您提供 Type of file(在本例中为“快捷方式”)。

有人知道访问Target type 的方法吗?谢谢。

For Each objFile in objFolder.Files

    ' Check that the file 'Target type' is not 'File Folder'
    If Not objFile.Type = "File Folder" Then
        objFSO.DeleteFile(desktop_locations(i) & objFile.Name)
    End If

Next

【问题讨论】:

    标签: vbscript


    【解决方案1】:

    您需要检查快捷方式的目标:

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set sh  = CreateObject("WScript.Shell")
    
    shortcut = "C:\path\to\some.lnk"
    
    Set lnk = sh.CreateShortcut(shortcut)
    If Not fso.FolderExists(lnk.TargetPath) Then
      'target doesn't exist or is not a folder
      fso.DeleteFile shortcut
    End If
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-28
      • 2012-06-14
      • 1970-01-01
      • 1970-01-01
      • 2017-10-22
      • 2015-02-17
      • 2018-07-17
      相关资源
      最近更新 更多