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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
| Attribute VB_Name = "where_pst"
'Option Explicit
'=======================================================================================
'This vbscript is used to read all the outlook profiles for that user from the registry
'to check for all types of PSTs (Archive, Personal Folders). It writes to
'a CSV file the path of the PST, the computer name its on, the username of the
'person logged on and the size of the PST. It then overwrites the path to the
'registry depending on the path required. Specially usefull when doing a migration.
'I am sure there is a much better way to write this code because there is a lot
'of repetition and i have no more time to do this so i will let you guys do that ;)
'It should work for outlook versions from 2000 and 2003.
'
'By: Carlos Bueno
'========================================================================================
Const HKEY_CURRENT_USER = &H80000001
Const BASE_KEY = "Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles"
Public fso, oNetwork, ws, ws2, objFileSystem
Public strComputer, tinyKeyPath, strOutputFile, objOutputFile, strInfo, strInfo2, BinOrStr, objreg, arrSubKeys
Sub pst_where()
'the network object used to connect to the network
Set oNetwork = CreateObject("WScript.Network")
'two objects to shell script.
Set ws = CreateObject("WScript.Shell")
Set ws2 = CreateObject("WScript.Shell")
'object used for later on getting the size of the PSTs
Set fso = CreateObject("Scripting.FileSystemObject")
strComputer = "."
'gets username of the person logged on
strInfo = oNetwork.UserName
'gets the computer name
strInfo2 = oNetwork.ComputerName
'A list of object required to write to the csv file and a variable that
'contains the name of the file (partial logged username). This is going
'to be used to write the data from the registry to the file along with
'logged on username and computer name.
strOutputFile = strInfo & "-pstpath.csv"
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile, True)
'object used to connect to the registry
Set objreg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
'This enumarates all the different profiles for the user
objreg.EnumKey HKEY_CURRENT_USER, BASE_KEY, arrSubKeys
'selects each profile
For Each subkey In arrSubKeys
subKeyPath = BASE_KEY & "\" & subkey
'This enumerate the subkeys of each profile and exposing
'the items that contain the data
objreg.EnumKey HKEY_CURRENT_USER, subKeyPath, arrTinyKeys
'selects each subkey within the profile
For Each tinyKey In arrTinyKeys
tinyKeyPath = subKeyPath & "\" & tinyKey
'resets the string to empty. Includes flags
PSTPath = ""
PSTPath5 = ""
PSTPath4 = ""
PSTPath6 = ""
myFlag = 0
BinOrStr = 0
'--------------------------------------------------------------------------------------
'Outlook 2000 reading and writting
'--------------------------------------------------------------------------------------
' On Error Resume Next
' PSTKeyName4 = "HKCU\" & tinyKeyPath & "\001e6700"
' strValue4 = ws.RegRead(PSTKeyName4)
' If Err Then
' Else
' If strValue4 <> 0 Then
' PSTPath4 = PSTPath4 & strValue4
' End If
'
'
' w = WriteToFilecsv(PSTPath4, PSTKeyName4)
'
'
' PSTKeyName5 = "HKCU\" & tinyKeyPath & "\01020fff"
' strValue5 = ws.RegRead(PSTKeyName5)
' For L = LBound(strValue5) To UBound(strValue5)
' If strValue5(L) <> 0 Then
' PSTPath5 = PSTPath5 & Chr(strValue5(L))
' End If
' Next
'
' PSTPath5 = Replace(PSTPath5, "8¡»å¡»+*VÂmspst.dllNITAù¿¸ª7Ùn", "")
' w = WriteToFilecsv(PSTPath5, PSTKeyName5)
' End If
' Err.Clear
'----------------------------------------------------------------------------------------
'Outlook 2003 reading and writting
'----------------------------------------------------------------------------------------
On Error Resume Next
PSTKeyName = "HKCU\" & tinyKeyPath & "\001f6700"
strValue = ws.RegRead(PSTKeyName)
If Err Then
Else
For L = LBound(strValue) To UBound(strValue)
If strValue(L) <> 0 Then
PSTPath = PSTPath & Chr(strValue(L))
End If
Next
w = WriteToFilecsv(PSTPath, PSTKeyName)
PSTKeyName6 = "HKCU\" & tinyKeyPath & "\01020fff"
strValue6 = ws.RegRead(PSTKeyName6)
For L = LBound(strValue6) To UBound(strValue6)
If strValue6(L) <> 0 Then
PSTPath6 = PSTPath6 & Chr(strValue6(L))
End If
Next
PSTPath6 = Replace(PSTPath6, "8¡»å¡»+*VÂmspst.dllNITAù¿¸ª7Ùn", "")
w = WriteToFilecsv(PSTPath6, PSTKeyName6)
End If
Err.Clear
Next
Next
'close and assign to nothing the object used to write to file
objOutputFile.Close
Set objFileSystem = Nothing
MsgBox "Finished outlook PST check..."
End Sub
'------------------------------------------------------------------------------------------------------
'The following two functions builds the hex number from a string and creates
'a binary variable that contains the data in bytes since the data
'needs to be in byte format in order to be entered onto the the registry.
'Also it adds back on the start of the string the hex number of the data that
'was "replaced" earlier just after reading from the registry.
Public Function StringToByteArray(Data, NeedNullTerminator)
Dim strAll
strAll = StringToHex4(Data)
If NeedNullTerminator Then
If BinOrStr = 2 Then
'2000
strAll = "0000000038A1BB1005E5101AA1BB08002B2A56C200006D737073742E646C6C00000000004E495441F9BFB80100AA0037D96E000000" & strAll
strAll = strAll & "00"
End If
If BinOrStr = 1 Then
'2003
strAll = "0000000038A1BB1005E5101AA1BB08002B2A56C200006D737073742E646C6C00000000004E495441F9BFB80100AA0037D96E00000000" & strAll
strAll = strAll & "0000"
End If
If BinOrStr = 3 Then
'2003
strAll = strAll & "0000"
End If
End If
intLen = Len(strAll) \ 2
ReDim arr(intLen - 1)
For i = 1 To Len(strAll) \ 2
arr(i - 1) = CByte("&H" & Mid(strAll, (2 * i) - 1, 2))
Next
BinOrStr = 0
StringToByteArray = arr
End Function
'returns the value as a hex number with the 00 added
Public Function StringToHex4(Data)
Dim strAll
For i = 1 To Len(Data)
strChar = Mid(Data, i, 1)
If myFlag = 0 Then
strTemp = Right("00" & Hex(AscW(strChar)), 4)
strAll = strAll & Right(strTemp, 2) & Left(strTemp, 2)
Else
strTemp = Hex(AscW(strChar))
strAll = strAll & Right(strTemp, 2)
End If
Next
myFlag = 0
StringToHex4 = strAll
End Function
'----------------------------------------------------------------------------------------------------------------
'function to write the data onto a csv file where the path in the registry was changed for the psts
Public Function WriteToFilecsv(myPath, myPSTKeyName)
myFsize = FormatNumber(fso.GetFile(myPath).Size, 0, , -1)
v = Split(tinyKeyPath, "\")
myProfName = Trim(v(6))
objOutputFile.WriteLine (strInfo & ";" & strInfo2 & ";" & myPath & ";" & myProfName & ";" & myFsize & ";" & myPSTKeyName)
End Function |
Partager