Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Need Script to Search for OST files on Local Drive

Posted on 2010-01-11
Medium Priority
Last Modified: 2012-05-08

I need help with a script that completes 3 tasks:

1. Stops Outlook application so OST is not locked.

2.  Searches for each .OST file within the C:\Documents and Settings\<username>\Local Settings\Application Data\Microsoft\Outlook directory and

3. Renames each file in said directory with another extension like .backup.  

Any help is appreciated. Thanks.
Question by:SugaBaby

Author Comment

ID: 26290527
I came up with this. Instead I seach using WMI, taking away directory restriction.

'On Error Resume Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery _
    ("Select * from CIM_DataFile Where Extension = 'ost'")

If colFiles.Count = 0 Then
End If

Set objFSO = CreateObject("Scripting.FileSystemObject")

For Each objFile in colFiles
    strNewName = objFile.Drive & objFile.Path & objFile.FileName & "." & objFile.Extension & ".BACKUP"
    errResult = objFile.Rename(strNewName)

LVL 20

Accepted Solution

ltlbearand3 earned 2000 total points
ID: 26423729
WMI is what you want to use here to accomplish your tasks.  I modified SugaBaby's code to include stopping outlook like you requested.

option explicit

Dim strComputer, objWMIService, objProcess, colProcess
Dim colFiles, objFile

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

' Stopping Outlook
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'outlook.exe'")
For Each objProcess in colProcess

' Look for all ost files on machine
Set colFiles = objWMIService.ExecQuery _
    ("Select * from CIM_DataFile Where Extension = 'ost'")

If colFiles.Count = 0 Then
	wscript.echo "No .OST Files were found."
End If

' Rename the Files to .BACKUP
For Each objFile in colFiles
    strNewName = objFile.Drive & objFile.Path & objFile.FileName & "." & objFile.Extension & ".BACKUP"
    errResult = objFile.Rename(strNewName)

Wscript.Echo "Re-naming is complete"

Open in new window


Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question