I have a VBS script that deletes everything from the start menu and adds it up again from scratch. I use this as a logon script in a domain. But last week I realized some people use different applications and those applications are not on a central share, so my question is is it possible to exclude certain folders from deletion from this script
Dim objShell, strCmd, intRunError, strFolder, objFileSys
Set objShell = CreateObject( "WScript.Shell" )
appDataLocation=objShell.ExpandEnvironmentStrings("%APPDATA%")
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(appDataLocation & "\Microsoft\Windows\Start Menu\Programs")
' delete all subfolders and files
For Each f In folder.SubFolders
On Error Resume Next
name = f.name
f.Delete True
Next
' delete all files in root folder
for each f in folder.Files
On Error Resume Next
name = f.name
f.Delete True
Next
Set objFileSys = CreateObject("Scripting.FileSystemObject")
objFileSys.GetFolder("\\test\dfstest\Start Menu\programs").Copy appDataLocation & "\Microsoft\Windows\Start Menu\Programs"
Set objFileSys = Nothing
Edit: Type mismatch?
Dim objShell, strCmd, intRunError, strFolder, objFileSys
Dim Exceptions()
Dim Exception
Dim i
Set objShell = CreateObject( "WScript.Shell" )
appDataLocation=objShell.ExpandEnvironmentStrings("%APPDATA%")
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(appDataLocation & "\Microsoft\Windows\Start Menu\Programs")
Exception(0) = appDataLocation & "\Microsoft\Windows\Start Menu\Programs\Access 2013"
Exception(1) = appDataLocation & "\Microsoft\Windows\Start Menu\Programs\Cameleon"
For Each sf in MyFolder.SubFolders
Exception = False
For i = LBound(Exceptions) to UBound(Exceptions)
If lCase(sf.Path) = lCase(Exceptions(i)) Then
Exception = True
Exit For
End If
Next
If Not Exception Then
deleteSubFolders
sf.Delete
End If
Next
Public Sub deleteSubFolders(byRef MyFolder, exclFolder)
Dim sf
For Each sf in MyFolder.SubFolders
If not (lCase(sf.Path) = lCase(exclFolder)) Then
deleteSubFolders sf, exclFolder
sf.Delete
End If
Next
End Sub
' delete all files in root folder
for each f in folder.Files
On Error Resume Next
name = f.name
f.Delete True
Next
Set objFileSys = CreateObject("Scripting.FileSystemObject")
objFileSys.GetFolder("\\test\dfstest\Start Menu\programs").Copy appDataLocation & "\Microsoft\Windows\Start Menu\Programs"
Set objFileSys = Nothing
excludeFolder
, but useexclFolder
:(.