簡體   English   中英

如何使用vbscript刪除多個文件夾,桌面和開始菜單快捷方式

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

我以前從未做過任何vbscript,所以我不知道我的問題是否很簡單。 以下是必須完成的步驟流程:

檢查是否存在,並在c:\\ test1處刪除一個文件夾,然后繼續。 如果找不到,請繼續。 檢查是否存在,如果找到,請刪除c:\\ programfiles \\ test2的文件夾,然后繼續。 如果找不到,請繼續。 檢查是否存在桌面快捷方式和開始菜單快捷方式,如果發現則將其刪除。 如果沒有退出。

我可以使用以下代碼刪除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

但是我需要運行一個腳本來刪除不同路徑下的2個文件夾,開始菜單中有2個快捷方式,在桌面上有2個快捷方式。

我正在嘗試使用以下代碼來刪除桌面上的快捷方式:

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

它對於台式機上的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