简体   繁体   English

如何使用vbscript删除多个文件夹,桌面和开始菜单快捷方式

[英]how to delete multiple folders,desktop and start menu shortcut using vbscript

I never did any vbscript before, so i don't know if my question is very easy one. 我以前从未做过任何vbscript,所以我不知道我的问题是否很简单。 Following is the flow of steps that has to be done : 以下是必须完成的步骤流程:

Check if exist and delete a folder at c:\\test1 if found and continue. 检查是否存在,并在c:\\ test1处删除一个文件夹,然后继续。 If not found continue. 如果找不到,请继续。 Check if exist and delete a folder at c:\\programfiles\\test2 if found and continue. 检查是否存在,如果找到,请删除c:\\ programfiles \\ test2的文件夹,然后继续。 If not found continue. 如果找不到,请继续。 Check if a desktop shortcut and start menu shortcut exist and delete if found. 检查是否存在桌面快捷方式和开始菜单快捷方式,如果发现则将其删除。 If not exit. 如果没有退出。

I could delete 2 folders with the following code: 我可以使用以下代码删除2个文件夹:

strPath1 = "C:\test1"
strPath1 = "C:\test1"
DeleteFolder strPath1
DeleteFolder strPath1
Function DeleteFolder(strFolderPath1)
Dim objFSO, objFolder
Set objFSO = CreateObject ("Scripting.FileSystemObject")
If objFSO.FolderExists(strFolderPath) Then
    objFSO.DeleteFolder strFolderPath, True
End If
Set objFSO = Nothing

But i need to run one script to delete 2 folders in different paths, 2 shortcuts one in start menu and one on desktop. 但是我需要运行一个脚本来删除不同路径下的2个文件夹,开始菜单中有2个快捷方式,在桌面上有2个快捷方式。

I was experimenting with this code to delete the shortcut on my desktop: 我正在尝试使用以下代码来删除桌面上的快捷方式:

Dim WSHShell, DesktopPath
   Set WSHShell = WScript.CreateObject("WScript.Shell")
   DesktopPath = WSHShell.SpecialFolders("Desktop")
   on error resume next
   Icon = DesktopPath & "\sample.txt"
   Set fs = CreateObject("Scripting.FileSystemObject")
   Set A = fs.GetFile(Icon)
   A.Delete
   WScript.Quit

It works fine for txt file on desktop, but how do i delete a shortcut for an application from desktop as well as start menu. 它对于台式机上的txt文件效果很好,但是如何从台式机以及“开始”菜单中删除应用程序的快捷方式。

strPath1 = "C:\test1"
strPath2 = "C:\test2"

DeleteFolder strPath1
DeleteFolder strPath2

DeleteShortcut

'-------------------------------------------------------
Sub DeleteFolder(strFolderPath)
  Set fso = CreateObject ("Scripting.FileSystemObject")
  If fso.FolderExists(strFolderPath) Then
    fso.DeleteFolder strFolderPath, True
  End If
End Sub

'-------------------------------------------------------    
Sub DeleteShortcut()
  Set WSHShell = WScript.CreateObject("WScript.Shell")
  DesktopPath = WSHShell.SpecialFolders("Desktop")

  shortcutPath = DesktopPath & "\MyShortcut.lnk"
  Set fso = CreateObject("Scripting.FileSystemObject")
  If fso.FileExists(shortcutPath) Then
    Set myFile = fso.GetFile(shortcutPath)
    myFile.Delete
  End If
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM