Question

Update PST file location on Logon via Script

Script to update PST File locationsBookmark:Question:
We are running a project to migrate the backend file location for 1000 user created PST files to a new 2008 File server. The server will not re-use the previous server name and we will not be able to use a DNS alias for the old server to point to the new one.

Users have historically used personal folders stored in their networked homedrives (Yes, we know it is not a Microsoft best practise methodology for PST file usage) and we are planning to move all pst files to a decidated PST file server and then update the path location to the pst files with no user impact or intervention.

I am looking at implementing a logon script to remap the pst file to the new location. The workflow will be as follows

Nighttime (After backups complete) robocopy pst files from \\oldserver\homedrive$ to \\newserver\pstdir$
Remove permissions to the source PST file
On user logon - map new network drive (P:\ to the \\newserver\pstdir$ directory (this will be a security locked down folder based on the user's name)
Logon script to query the registry or mapi profile of the user and for every pst file connected (Some users have more than 1) change the path from M:\ (current user homedrive mapping) to P:\ (preserving the rest of the path, for example if a user had M:\MyMail\October-Archive.pst file then the remap should be P:\MyMail\October-Archive.pst)

I am ok for the 1st parts of the problem, but I am stuck on the Logon script, as the value stored in the registry is a hexidecimal string. So I need to query all outlook profiles for the user, compile an array of pst file string locations, decode the strings, rewrite the new path, encode the string and write it back.

I have found a few scripts on the net that in part achieve some aspects of this, but nothing that provides a complete solution.

Mapi profile information is stored in the registry here "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles"

The key name for a PST file is either "01020fff" "001f6700" (Example below)

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Default Outlook Profile\93abdcf58c80884b92c1b8c1b272dc12
    01023414    REG_BINARY    4E495441F9BFB80100AA0037D96E0000
    001f300a    REG_BINARY    6D0073007000730074002E0064006C006C000000
    001f3d13    REG_BINARY    7B00360034003800350044003200360032002D0043003200410043002D0031003100440031002D0041004400330045002D003100300041003000430039003100310043003900430030007D000000
    00033e03    REG_BINARY    21000000
    00033009    REG_BINARY    00000000
    001f3001    REG_BINARY    50006500720073006F006E0061006C00200046006F006C0064006500720073000000
    001f3006    REG_BINARY    50006500720073006F006E0061006C00200046006F006C0064006500720073000000
    01023d0c    REG_BINARY    2BDB2EC4365E81428904AB3D06E7FD3E
    001f3d09    REG_BINARY    4D005300550050005300540020004D0053000000
    00036770    REG_BINARY    00000080
    00036702    REG_BINARY    00000010
    01020fff    REG_BINARY    0000000038A1BB1005E5101AA1BB08002B2A56C200006D737073742E646C6C00000000004E495441F9BFB80100AA0037D96E0000000043003A005C00540065006D0070005C00540065007300740031002E007000730074000000
    001f6700    REG_BINARY    43003A005C00540065006D0070005C00540065007300740031002E007000730074000000
    001f3004    REG_BINARY    0000
    01020ff9    REG_BINARY    636E08EC45E2F449AB50A4F2AB97DDF3

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-06-29 at 17:45:49ID24531865
Tags

VB

,

VBScript

,

WMI

,

Outlook

,

Logon

,

PST

,

File

Topics

Windows Networking

,

VB Script

,

Outlook Groupware Software

,

Exchange Email Server

,

Microsoft Server

Participating Experts
1
Points
500
Comments
7

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Compressing .PST
    I would like to know if there is a way (an command line utility, for example) for me to compact users´ .PST during logon.
  2. Setting Registry Permissions for HKCU
    Is there a way to set permissions on keys under HKEY_CURRENT_USER for multiple users? There is a program that we run under a Citrix environment that requires Power User access. I would like to restrict user rights on the server. I did some checking and narrowed down the re...
  3. Using Regini to change HKCU
    I am wanting to use Regini to change a registry entry in HKCU in a logon script. The info in the resource kit says "HKEY_CURRENT_USER is converted to \Registry\User\User_SID, where User_SID is the current user's security identifier (SID)." The problem is that for ...
  4. Converting Historical DateTime from GMT-PST Including DST.
    Client has 60+ years historical data that includes Date_Time stamp on records. The Date_Time stamp was stored relative to GMT. The GMT Date_Time stamp was recorded in the historical records which were, and remain, in the PST zone. Client needs historical data converted. T...
  5. PST is not available for offline use
    Using SBS 2003, we have implemented Folder Redirection successfully. The client did not want to use Exchange, so we converted their mailboxes to a PST file. However, we still want to "protect" the PST's from loss, so I placed each user's PST in thier MY DOCUMENTS ...
  6. Unable to add registry key to HKCU on terminal server with l…
    Hi, I am trying to add the following registry key with a log on script: regedit /s "HKCU\Software\Policies\Microsoft\Office\12.0\Outlook\Security\PromptSimpleMAPISend", 2, "REG_DWORD" It is telling me that I don't have permissions. I have checked my GPO ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: ServerManagementTeamPosted on 2009-06-29 at 17:51:08ID: 24741394

I have made a bit of headway with this and I can enumerate the PST files that match a criteria. However, I am now stuck on writing the translated value back to the registry. Code snip below

Example output below

Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

D:\Mail\Test.pst  Does not need to be remapped
PST Found at location  M:\Test\Test.pst
Translating occurence of M:\ to P:\ - New location is now  P:\Test\Test.pst
Translating  P:\Test\Test.pst To HEX value to add to the Registry, new value is  50 3A 5C 54 65 73 74 5C 54 65 73 74 2E 70 73 74 0

50,00,3A,00,5C,00,54,00,65,00,73,00,74,00,5C,00,54,00,65,00,73,00,74,00,2E,00,70,00,73,00,74,00,0,00,

Option Explicit
Dim go_fso, go_outlook, go_namespace         
Dim gl_folders, gl_files, gl_psts                        
Dim strNewText
Call s_init()
Call s_main()
WScript.Quit(0)
 
Sub s_init()
  Set go_fso = CreateObject( "Scripting.FileSystemObject" )
  Set go_outlook = CreateObject( "Outlook.Application" )
  Set go_namespace = go_outlook.GetNameSpace( "MAPI" )
End Sub
 
Sub s_main()
  Const cs_fac = "%s_main, "
  Dim lo_folder, ls_path                            
 
  For Each lo_folder In go_outlook.Session.Folders
        ls_path = GetStorePath( lo_folder.StoreID )
   		Dim str1
    	Dim str2
    	Dim arrStr
    	Dim oReg
       	arrStr = Split(ls_path, ":", -1,1)
    	str1 = UCase(arrStr(0))
     	str2 = UCase("M")
		If str1 = str2 Then
		strNewText = Replace(ls_path, "M:\", "P:\")
		WScript.Echo "PST Found at location ", ls_path & vbCrLf
    	WScript.Echo "Translating occurence of M:\ to P:\ - New location is now ", strNewText & vbCrLf
		WScript.Echo "Translating ", strNewText, "To HEX value to add to the Registry, new value is ", StringToHex4(strNewText) & vbCrLf
		Dim StringForArray
		StringForArray = Replace(StringToHex4(strNewText), " ", ",00,")
		WScript.Echo StringForArray
		WriteValue(StringForArray)
		Else
		WScript.Echo ls_path, " Does not need to be remapped"
		End If
		Next
End Sub
 
Function GetStorePath(strStoreID)
    Dim intStart
    Dim intEnd
    Dim strProvider
    Dim strPathRaw
    intStart = InStr(9, strStoreID, "0000") + 4
    intEnd = InStr(intStart, strStoreID, "00")
    strProvider = Mid(strStoreID, intStart, intEnd - intStart)
    strProvider = Hex2ToString(strProvider)
    Select Case LCase(strProvider)
        Case "mspst.dll", "pstprx.dll"
            If Right(strStoreID, 6) = "000000" Then
                '2003
                intStart = InStrRev(strStoreID, "00000000") + 8
                strPathRaw = Mid(strStoreID, intStart)
                GetStorePath = Trim(Hex4ToString(strPathRaw))
            Else
                '97
                intStart = InStrRev(strStoreID, "000000") + 6
                strPathRaw = Mid(strStoreID, intStart)
                GetStorePath = Trim(Hex2ToString(strPathRaw))
            End If
 
        Case "msncon.dll"
            intStart = InStrRev(strStoreID, "00", Len(strStoreID) - 2) + 2
            strPathRaw = Mid(strStoreID, intStart)
            GetStorePath = Trim(Hex2ToString(strPathRaw))
        Case "emsmdb.dll"
            GetStorePath = "Exchange store"
        Case Else
            GetStorePath = "Unknown store path"
    End Select
End Function
 
Public Function Hex4ToString(Data)
    Dim strTemp
    Dim strAll
    Dim i
    For i = 1 To Len(Data) Step 4
        strTemp = Mid(Data, i, 4)
        strTemp = "&H" & Right(strTemp, 2) & Left(strTemp, 2)
        strAll = strAll & ChrW(Eval(strTemp))
    Next
    Hex4ToString = strAll
End Function
 
Public Function Hex2ToString(Data)
    Dim strTemp
    Dim strAll
    Dim i
    For i = 1 To Len(Data) Step 2
        strTemp = "&H" & Mid(Data, i, 2)
        strAll = strAll & ChrW(Eval(strTemp))
    Next
    Hex2ToString = strAll
End Function
 
Public Function StringToHex4(Data)
	Dim i, sVAL
	For i = 1 To Len(Data) 
	sVAL = sVAL & Hex(Asc(Mid(Data,i,1))) & " "
	StringToHex4 = sVAL
Next
 
End Function
 
 
 
Public Function WriteValue(Data)
 
Const HKEY_CURRENT_USER = &H80000001
Dim objRegistry, strPath, uBinary, Return
 
Set objRegistry = GetObject("Winmgmts:root\default:StdRegProv")
 
strPath = "Software\MyKey"
uBinary = Data
Return = objRegistry.SetBinaryValue(HKEY_CURRENT_USER, strPath, "MyBinaryNamedValue", uBinary)
 
If (Return = 0) And (Err.Number = 0) Then
    Wscript.Echo "Binary value added successfully"
Else
    ' An error occurred
End If
 
End Function
 
Public Function WriteValue(Data)
 
Const HKEY_CURRENT_USER = &H80000001
Dim strComputer
Dim strKeyPath
Dim strValueName
Dim arrValues
Dim errReturn
Dim objRegistry
 
strComputer = "."
 
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
 
strKeyPath = "Software"
strValueName = "BinaryTest"
arrValues = Array(Data)
 
errReturn = objRegistry.SetBinaryValue (HKEY_CURRENT_USER, strKeyPath, strValueName, arrValues)
 
End Function
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:

Select allOpen in new window

 

by: RobSampsonPosted on 2009-07-03 at 20:26:04ID: 24775604

Hi there,

I haven't used the SetBinaryValue method that much and I can't test it out just yet...
http://msdn.microsoft.com/en-us/library/aa393286(VS.85).aspx

But, would it be easier to write a .reg file with the script, and include your binary string in that reg file, then use the Run method of the WScript.Shell object to run
regedit / s <regfilepath>

Would that work?

Regards,

Rob.

 

by: ServerManagementTeamPosted on 2009-07-05 at 15:51:57ID: 24781593

The problem though is that the script as it is does not give me the registry path of where to write the value back to.

Function GetStorePath(strStoreID)
 returns PST file paths, but it does not query the registry directly, instead it calls two dlls to get the info store path, but that does not return the full registry path for me to translate and write back

 

by: RobSampsonPosted on 2009-07-05 at 17:36:22ID: 24781823

Hmmm, if you're only moving the PST files in the bacfground, then perhaps the code from here can help:
http://www.outlookcode.com/codedetail.aspx?id=1471

It's built to run in a Microsoft Macro of some sort, preferably an Outlook macro I would guess.  It has DetachPST, MoveFiles, and AttachPST functions, that may suit what you're looking for.

Regards,

Rob.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...