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

Posted by user1756858 on Stack Overflow See other posts from Stack Overflow or by user1756858
Published on 2012-10-31T16:30:43Z Indexed on 2012/10/31 17:00 UTC
Read the original article Hit count: 194

Filed under:
|

I never did any vbscript before, so i don't know if my question is very easy one. 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. If not found continue. Check if exist and delete a folder at c:\programfiles\test2 if found and continue. 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:

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.

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.

© Stack Overflow or respective owner

Related posts about Windows

Related posts about vbscript