Solved

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

Posted on 2012-03-29
2
428 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

738 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