Solved

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

Posted on 2012-03-29
2
427 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
ID: 37789961
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
ID: 37795580
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

830 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