Avatar of BRPsysadmin
BRPsysadmin
 asked on

VBScript to enumerate folders and delete a file if it exists

I am installing Symantec Endpoint Protection 11, and doing so there is a problem with the outlook add-in. Symantec recommends deleting C:\Documents and Settings\%username%\Local Settings\Application Data\Microsoft\Outlook\extend.dat
I'm weak in scripting so I'm hoping someone out there can help with a script to do the following:
1. Close outlook
2. Enumerate all the "username" folders.
3. Delete any extend.dat files that exist.
4. Install the setup.exe

Or if there is a better way to do this, that'd be great too.
VB ScriptInstallation

Avatar of undefined
Last Comment
prashanthd

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
jawa29

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
BRPsysadmin

ASKER
I will test and get back to you
Thanks in advance
prashanthd

Please try the following..
Error handling included for file deletion and installation included

On Error Resume Next
' Instantiate the various objects

On Error Resume Next
' Instantiate the various objects

strComputer = "."
MyApp = """C:\MyApplication\Setup.exe"" /Q" 'change only the path to setup file leave the remaining

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set oWSH    = CreateObject("WScript.Shell")
Set oFSO    = CreateObject("Scripting.FileSystemObject")

'Terminate outlook

Set colProcessList = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'outlook.exe'")

For Each objProcess in colProcessList
    objProcess.Terminate()
Next

' Get the Allusers profile folder path first and from this determine profiles parent folder
'
sAllUsersProfile    = oWSH.ExpandEnvironmentStrings("%ALLUSERSPROFILE%")
Set oAllUsersFolder = oFSO.GetFolder(sAllUsersProfile)
sProfilesRoot       = oAllUsersFOlder.ParentFolder

' Now enumerate all existing user profile folders

Set oFolder            = oFSO.GetFolder(sProfilesRoot)
Set colFSOSubfolders   = oFolder.Subfolders

' Now go through each existing user profile folder looking for the designated folder to delete

For Each objSubfolder In colFSOSubfolders
       
    filepath=objSubFolder.Path & "\Local Settings\Application Data\Microsoft\Outlook\extend.dat"
    'WScript.Echo filepath
   
    If oFSO.FileExists(filepath) Then
        Err.Clear
        oFSO.DeleteFile(filepath)
        If Err.Number<>0 Then
            WScript.Echo "Cannot delete file - "& filepath &" Err Number:"& Err.Number & " Err Description: " & Err.Description
        End If
    End If
   
Next

'Install Application

Set oShell = CreateObject("WScript.Shell")
i = 0
i = oShell.Run(MyApp, 1 ,True)

If i=0 Then
      WScript.Echo "Application successfully installed"
Else
      WScript.Echo "Application installation error, please check"
End If

Set oShell = Nothing




Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes