Solved

Need Find and Replace Batch file to overwrite .MST files located in multiple locations

Posted on 2012-03-29
2
424 Views
Last Modified: 2012-04-02
Request:
I need a batch file that finds a file on a user's PC and replaces it with a different file with the same name.  This would be run in a login script.

Background:

I have an organization that has a large number of legacy PC's with Office 2003.  The staff utilized the Office Customization Tool to create user's Outlook profiles when they logged onto a PC for the first time.  

The MST files has the Outlook profile point to a legacy Exchange 2003 server which needs to be decommissioned.  If the legacy Exchange 2003 server is decommissioned and a new user logs onto a machine with the old MST file on it they will be pointed to an Exchange server that no longer exists.

I need to replace the incorrect MST file with the new MST file that points the profile to the proper server.  

I cannot use (copy \\server\file share\file.mst c:\file.mst /y) due to the mst files residing under MSOCache and having different locations. The batch file will need to be able to find the MST and replace it with the updated version.

 Thank you.
0
Comment
Question by:advserver
2 Comments
 
LVL 20

Accepted Solution

by:
ltlbearand3 earned 500 total points
Comment Utility
Here is an idea you can try.  The more information you can provide about he mst file, the more efficient this script will run.  It will look through all files for a match (this could be time consuming) and then will copy a file from a network location to the local drive.  Make sure to update the two variables at the start with the proper information for your situation.  

' Put the pattern of the mst file match here
strPattern = "yourfilename.mst"
' Place path and location of new file here
strNewFile = "\\server\folder\newfile.mst"

strComputer = "."
Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery("Select * from CIM_Datafile where name like '%" & strPattern & "'")

For Each objFile in colFiles
	objFSO.CopyFile strNewFile, objFile.Path
Next

wscript.quit

Open in new window


-Bear
0
 
LVL 4

Author Comment

by:advserver
Comment Utility
Thank you for your suggestion! I attempted something similar but ultimately the code below ended up working.  

dir "c:\MSOCache\File.mst" /a:-d /b /s > %TEMP%\store.txt
FOR /F "eol=; tokens=1,2,3* delims=, " %%i in (%TEMP%\store.txt) do copy \\Server\share\File.mst "%%i %%j %%k" /y
del /F %TEMP%\store.txt
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now