Solved

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

Posted on 2012-03-29
2
425 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
User profile Size Report 3 64
how to get the largest file size? 33 57
Sending Attachment via CDO 3 59
change the windows script file to BAT 10 30
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
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 …
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

867 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

12 Experts available now in Live!

Get 1:1 Help Now