【发布时间】:2014-04-22 15:28:32
【问题描述】:
我将如何制作一个批处理文件,该文件将在计算机上搜索所有无效的快捷方式(快捷方式未链接到不再存在的文件。)并删除它们。最好是批量完成,但如果批量执行有问题,VBScript 也可以。
【问题讨论】:
标签: batch-file vbscript shortcut delete-file
我将如何制作一个批处理文件,该文件将在计算机上搜索所有无效的快捷方式(快捷方式未链接到不再存在的文件。)并删除它们。最好是批量完成,但如果批量执行有问题,VBScript 也可以。
【问题讨论】:
标签: batch-file vbscript shortcut delete-file
回馈一些东西。 KIX 对我来说效果更好,我制作了这个脚本来从用户中删除 Citrix pnagen.exe LNK 文件,因为 Receiver 4.3 在安装期间没有清理:
;---------------------------------------------------------------------
; Filename..: RemoveIcaLNK.kix
; Author....: Arild Skullerud inspired by enumfiles by David M. Stein
; Date......: 09/24/15
; Purpose...: Remove all LNK files with a set of folders
; Removes only LNK files pointing to:
; "C:\Program Files (x86)\Citrix\ICA Client\pnagent.exe"
; Created with the purpose of cleaning up LNK files before
; installing Citrix Receiver 4.3 as it fails cleaning up.
;---------------------------------------------------------------------
; Simple folders I could remove in a simple way
RD ("%AppData%\Microsoft\Windows\Start Menu\Programs\XenApp\") /s
RD ("%AppData%\Microsoft\Windows\Start Menu\Programs\Metaframe\") /s
;--------------------------------------------------------------------------------------------------------------
; Deletes $lnkfilepath pointing to the lnk file to be deleted
; $targetpath is the EXE the lnk points to ( or any other filetype)
;--------------------------------------------------------------------------------------------------------------
Function WshRmInvShortCut($lnkfilepath,$targetpath)
dim $shell,$shortcut
$shell = createobject("wscript.shell")
if $shell
$shortcut = $shell.createshortcut("$lnkfilepath")
if $shortcut
if $shortcut.targetpath=$targetpath
; Some debug lines
;? $shortcut.targetpath
;? $lnkfilepath
; Delete only the LNK file that points to the correct exe here
;DEL ($lnkfilepath) /h /s
$shortcut = 0
endif
endif
$shell = 0
endif
exit @error
EndFunction
;--------------------------------------------------------------------------------------------------------------
; Searches $StartPath for files ending with $ext and calls WshRmInvShortCut for removing them
; $targetpath is the exe the lnk points to
;--------------------------------------------------------------------------------------------------------------
Function Enum_Files($StartPath, $Ext)
Dim $fName
$fName = Dir("$StartPath\*.$Ext")
While $fName <> "" And @ERROR = 0
WshRmInvShortCut($StartPath+\+$fname,$targetpath)
$fName = Dir()
Loop
EndFunction
;--------------------------------------------------------------------------------------------------------------
; Script running from here
; Path to pnagent.exe
$targetpath = "C:\Program Files (x86)\Citrix\ICA Client\pnagent.exe"
; Filename ending
$Ext = "lnk"
; Path to folder I want to search and empty of lnk files
$StartPath="%appdata%\Microsoft\Windows\Start Menu\Programs"
; Calling script for first path
$=Enum_Files($StartPath, $Ext)
; Path to folder I want to search and empty of lnk files
$StartPath="%userprofile%\Desktop"
; Calling script for second path
$=Enum_Files($StartPath, $Ext)
:END
【讨论】:
这里有一个 vbscript 来做。
DeleteShortCut "C:\"
Sub DeleteShortcut(Folder)
For Each Subfolder in Folder.SubFolders
Set objFolder = objFSO.GetFolder(Subfolder.Path)
Set colFiles = objFolder.Files
For Each objFile in colFiles
If objFile.Name <> "Desktop.lnk" And UCase(objFile.Type) = "SHORTCUT" Then
Set objshortcut = objshell.CreateShortcut(objFile.Path)
filepath = objshortcut.TargetPath
If objFSO.FileExists(filepath) = False Then
WScript.Echo "Removing invalid ShortCut :" & objFile.Path
objFSO.DeleteFile(objFile.Path)
End If
End If
Next
DeleteShortcut Subfolder
Next
End Sub
【讨论】: