Bài vi?t này mô t? làm th? nào đ? l?p tr?nh l?y
thông tin v? kích thư?c c?a h?p thư trên m?t máy ch? đang ch?y Microsoft Exchange
b?ng cách s? d?ng Microsoft Visual C, Microsoft Visual C++, Microsoft Visual
BASIC, và Microsoft Visual Basic script Edition (VBScript).
Cách ti?p c?n MAPI m? r?ng
Programming Languages Ngôn ng? có s?n: C tr?c quan, Visual c ++
Exchange Server Phiên b?n: Trao đ?i máy ch? 5.5, Exchange 2000, và Exchange 2003
M? r?ng MAPI
cung c?p các
IExchangeManageStore giao di?n đ? có đư?c qu?n l? thông tin t? m?t cu?c trao đ?i
lưu tr? thông tin. Giao di?n này cung c?p các
GetMailboxTable ch?c năng, mà tr? v? m?t
IMAPITable giao di?n có ch?a thông tin v? các h?p thư trên m?t
h? ph?c v? c? th?. Lưu ? r?ng hàm này đ?i h?i quy?n truy c?p vào hành chính
máy ch? đang ch?y Exchange Server.
B?ng này bao g?m m?t
c?t cung c?p thông tin v? kích thư?c c?a m?i h?p thư. Các
PR_MESSAGE_SIZE b?t đ?ng s?n có kích thư?c (trong byte) c?a h?p thư.
Đ? bi?t thêm chi ti?t, nh?p vào s? bài vi?t sau đây đ? xem bài vi?t trong cơ s? ki?n th?c Microsoft:
200160
(http://support.microsoft.com/kb/200160/
)
Làm th? nào đ? l?p qua h?p thư trên trao đ?i b?ng cách s? d?ng GetMailboxTable
Cách ti?p c?n CDO 1.21
Programming Languages Ngôn ng? có s?n: VBScript, Visual Basic, Visual C, Visual c ++
Exchange Server Phiên b?n: Trao đ?i máy ch? 5.5, Exchange 2000, và Exchange 2003
B?n có th? s? d?ng
C?ng tác d? li?u đ?i tư?ng (CDO) 1.21 đ? ki?m tra các tài s?n cùng m?t ngày m?t ngư?i s? d?ng
c?a hàng h?p thư thông qua CDO
InfoStore đ?i tư?ng. Trong cách ti?p c?n này, ?ng d?ng c?a b?n ph?i đăng nh?p vào m?t
h?p thư trư?c khi các ?ng d?ng có th? ki?m tra này b?t đ?ng s?n. Đi?u này có ngh?a là c?a b?n
?ng d?ng ph?i có quy?n truy c?p cho t?t c? các h?p thư trên máy ch?. Đi?u này ti?p c?n c?ng
yêu c?u mà b?n t?o ra m?t danh sách các h?p thư trên máy ch? và sau đó l?p
qua chúng trong m?.
Các m?u sau đây là m?t đơn gi?n, VBScript m?
m?u mà có th? ki?m tra thu?c tính này vào m?t h?p thư. S? d?ng m?u này, dán các
sau m? trong m?t t?p tin văn b?n m?i, và sau đó đ?t tên t?p tin Mailboxsize.vbs:
'This script logs on to a server that is running Exchange Server and
'displays the current number of bytes that are used in the user's
'mailbox and the number of messages.
' USAGE: cscript MailboxSize.vbs SERVERNAME MAILBOXNAME
' This requires that CDO 1.21 is installed on the computer.
' This script is provided AS IS. It is intended as a SAMPLE only.
' Microsoft offers no warranty or support for this script.
' Use at your own risk.
' Get command line arguments.
Dim obArgs
Dim cArgs
Set obArgs = WScript.Arguments
cArgs = obArgs.Count
Main
Sub Main()
Dim oSession
Dim oInfoStores
Dim oInfoStore
Dim StorageUsed
Dim NumMessages
Dim strProfileInfo
Dim sMsg
On Error Resume Next
If cArgs <> 2 Then
WScript.Echo "Usage: cscript MailboxSize.vbs SERVERNAME MAILBOXNAME"
Exit Sub
End If
'Create Session object.
Set oSession = CreateObject("MAPI.Session")
if Err.Number <> 0 Then
sMsg = "Error creating MAPI.Session."
sMsg = sMsg & "Make sure CDO 1.21 is installed. "
sMsg = sMsg & Err.Number & " " & Err.Description
WScript.Echo sMsg
Exit Sub
End If
strProfileInfo = obArgs.Item(0) & vbLf & obArgs.Item(1)
'Log on.
oSession.Logon , , False, True, , True, strProfileInfo
if Err.Number <> 0 Then
sMsg = "Error logging on: "
sMsg = sMsg & Err.Number & " " & Err.Description
WScript.Echo sMsg
WScript.Echo "Server: " & obArgs.Item(0)
WScript.Echo "Mailbox: " & obArgs.Item(1)
Set oSession = Nothing
Exit Sub
End If
'Grab the information stores.
Set oInfoStores = oSession.InfoStores
if Err.Number <> 0 Then
sMsg = "Error retrieving InfoStores Collection: "
sMsg = sMsg & Err.Number & " " & Err.Description
WScript.Echo sMsg
WScript.Echo "Server: " & obArgs.Item(0)
WScript.Echo "Mailbox: " & obArgs.Item(1)
Set oInfoStores = Nothing
Set oSession = Nothing
Exit Sub
End If
'Loop through information stores to find the user's mailbox.
For Each oInfoStore In oInfoStores
If InStr(1, oInfoStore.Name, "Mailbox - ", 1) <> 0 Then
'&HE080003 = PR_MESSAGE_SIZE
StorageUsed = oInfoStore.Fields(&HE080003)
if Err.Number <> 0 Then
sMsg = "Error retrieving PR_MESSAGE_SIZE: "
sMsg = sMsg & Err.Number & " " & Err.Description
WScript.Echo sMsg
WScript.Echo "Server: " & obArgs.Item(0)
WScript.Echo "Mailbox: " & obArgs.Item(1)
Set oInfoStore = Nothing
Set oInfoStores = Nothing
Set oSession = Nothing
Exit Sub
End If
'&H33020003 = PR_CONTENT_COUNT
NumMessages = oInfoStore.Fields(&H36020003)
if Err.Number <> 0 Then
sMsg = "Error Retrieving PR_CONTENT_COUNT: "
sMsg = sMsg & Err.Number & " " & Err.Description
WScript.Echo sMsg
WScript.Echo "Server: " & obArgs.Item(0)
WScript.Echo "Mailbox: " & obArgs.Item(1)
Set oInfoStore = Nothing
Set oInfoStores = Nothing
Set oSession = Nothing
Exit Sub
End If
sMsg = "Storage Used in " & oInfoStore.Name
sMsg = sMsg & " (bytes): " & StorageUsed
WScript.Echo sMsg
WScript.Echo "Number of Messages: " & NumMessages
End If
Next
' Log off.
oSession.Logoff
' Clean up memory.
Set oInfoStore = Nothing
Set oInfoStores = Nothing
Set oSession = Nothing
End Sub
Cách ti?p c?n ActiveX Data Objects (ADO)
Programming Languages Ngôn ng? có s?n: VBScript, Visual Basic, Visual C, Visual c ++
Exchange Server Phiên b?n: Exchange 2000 và Exchange 2003
Trong Exchange 2000 và Exchange 2003, b?n có th? truy c?p
kho thông tin Exchage thông qua ActiveX Data Objects (ADO). Không có b?t đ?ng s?n
đó đư?c lưu tr? trên h?p thư ch?a t?ng kích thư?c. Tuy nhiên, m?i thư m?c trong
m?t h?p thư ngư?i s? d?ng có kích thư?c c?a nó đư?c lưu tr? trong m?t l?nh v?c đư?c đ?t tên theo
http://schemas.Microsoft.com/MAPI/proptag/x0e080003. Đi?u này tương ?ng v?i b?t đ?ng s?n MAPI,
PR_MESSAGE_SIZE.
B?ng cách thêm kích thư?c c?a t?t c? các thư m?c trong m?t ngư?i s? d?ng
h?p thư, t?ng kích thư?c c?a h?p thư có th? đư?c tính. Đ? th?c hi?n vi?c này, b?n s? d?ng m?t
Theo cây nông đ? đ? quy đi qua các thư m?c trong h?p thư. M?c dù
b?n có th? s? d?ng m?t theo cây SÂU, cách ti?p c?n này tránh v? trong nh?ng v?n đ?
mà theo cây SÂU làm tăng. Đ? có thêm thông tin v? các v?n đ? v?i m?t theo cây SÂU, b?m s? bài vi?t sau đây đ? xem bài vi?t trong cơ s? ki?n th?c Microsoft:
216076
(http://support.microsoft.com/kb/216076/
)
Truy c?p vào thư m?c kho thông tin có th? tr? nên ch?m
Trong cách ti?p c?n này, b?n ph?i ch?y m? c?a b?n các
máy ch? đang ch?y Exchange 2000. OLE DB nhà cung c?p cho vi?c trao đ?i (EXOLEDB)
không th? truy c?p h?p thư t? xa.
Các m?u sau đây là m?t đơn gi?n
VBScript m?u m? mà có th? truy xu?t kích thư?c c?a h?p thư. Đ? s? d?ng
m?u, dán sau đây m? trong m?t t?p tin văn b?n m?i, và sau đó đ?t tên t?p tin
Mailboxsize.VBS:
'This script logs on to a server that is running Exchange 2000 or 2003 and
'displays the current number of bytes that are used in the user's
'mailbox.
' USAGE: cscript MailboxSize.vbs DOMAINNAME MAILBOXNAME
' You must run this code on the computer that is running Exchange 2000 or 2003.
' This script is provided AS IS. It is intended as a SAMPLE only.
' Microsoft offers no warranty or support for this script.
' Use at your own risk.
' Get command line arguments
Dim obArgs
Dim cArgs
Dim iSize
Set obArgs = WScript.Arguments
cArgs = obArgs.Count
Main
Sub Main()
Dim sConnString
On Error Resume Next
If cArgs <> 2 Then
WScript.Echo "Usage: cscript MailboxSize.vbs DOMAINNAME MAILBOXNAME"
Exit Sub
End If
' Set up connection string to mailbox.
sConnString = "file://./backofficestorage/" & obArgs.Item(0)
sConnString = sConnString & "/mbx/" & obArgs.Item(1) & "/NON_IPM_SUBTREE"
WScript.Echo sConnString
iSize = 0
RecurseFolder(sConnString)
WScript.Echo "Mailbox Size: " & iSize
End Sub
Public Sub RecurseFolder(sConnString)
Dim oConn
Dim oRecSet
Dim sSQL
' Set up SQL SELECT statement.
sSQL = "SELECT ""http://schemas.microsoft.com/mapi/proptag/x0e080003"", "
sSQL = sSQL & """DAV:href"", "
sSQL = sSQL & """DAV:hassubs"" "
sSQL = sSQL & "FROM SCOPE ('SHALLOW TRAVERSAL OF """ & sConnString
sSQL = sSQL & """') WHERE ""DAV:isfolder"" = true"
WScript.Echo sSQL
' Create Connection object.
Set oConn = CreateObject("ADODB.Connection")
if Err.Number <> 0 then
WScript.Echo "Error creating ADO Connection object: " & Err.Number & " " & Err.Description
end if
' Create RecordSet object.
Set oRecSet = CreateObject("ADODB.Recordset")
if Err.Number <> 0 then
WScript.Echo "Error creating ADO RecordSet object: " & Err.Number & " " & Err.Description
Set oConn = Nothing
Exit Sub
end if
' Set provider to EXOLEDB.
oConn.Provider = "Exoledb.DataSource"
' Open connection to folder.
oConn.Open sConnString
if Err.Number <> 0 then
WScript.Echo "Error opening connection: " & Err.Number & " " & Err.Description
Set oRecSet = Nothing
Set oConn = Nothing
Exit Sub
end if
' Open Recordset of all subfolders in folder.
oRecSet.CursorLocation = 3
oRecSet.Open sSQL, oConn.ConnectionString
if Err.Number <> 0 then
WScript.Echo "Error opening recordset: " & Err.Number & " " & Err.Description
oRecSet.Close
oConn.Close
Set oRecSet = Nothing
Set oConn = Nothing
Exit Sub
end if
if oRecSet.RecordCount = 0 then
oRecSet.Close
oConn.Close
Set oRecSet = Nothing
Set oConn = Nothing
Exit Sub
end if
' Move to first record.
oRecSet.MoveFirst
if Err.Number <> 0 then
WScript.Echo "Error moving to first record: " & Err.Number & " " & Err.Description
oRecSet.Close
oConn.Close
Set oRecSet = Nothing
Set oConn = Nothing
Exit Sub
end if
' Loop through all of the records, and then add the size of the
' subfolders to obtain the total size.
While oRecSet.EOF <> True
' Increment size.
iSize = iSize + oRecSet.Fields.Item("http://schemas.microsoft.com/mapi/proptag/x0e080003")
' If the folder has subfolders, recursively call RecurseFolder to process them.
If oRecSet.Fields.Item("DAV:hassubs") = True then
RecurseFolder oRecSet.Fields.Item("DAV:href")
End If
' Move to next record.
oRecSet.MoveNext
if Err.Number <> 0 then
WScript.Echo "Error moving to next record: " & Err.Number & " " & Err.Description
Set oRecSet = Nothing
Set oConn = Nothing
Exit Sub
end if
wend
' Close Recordset and Connection.
oRecSet.Close
if Err.Number <> 0 then
WScript.Echo "Error closing recordset: " & Err.Number & " " & Err.Description
Set oRecSet = Nothing
Set oConn = Nothing
Exit Sub
end if
oConn.Close
if Err.Number <> 0 then
WScript.Echo "Error closing connection: " & Err.Number & " " & Err.Description
Set oRecSet = Nothing
Set oConn = Nothing
Exit Sub
end if
' Clean up memory.
Set oRecSet = Nothing
Set oConn = Nothing
End Sub
Đ? thêm thông tin
v? ch? đ? này và m?t m?u Visual C++ truy kích thư?c c?a
h?p thư, nh?p vào s? bài vi?t sau đây đ? xem bài vi?t trong cơ s? ki?n th?c Microsoft:
291368
(http://support.microsoft.com/kb/291368/
)
Làm th? nào đ? xác đ?nh kích thư?c c?a h?p thư Exchange 2000 Server v?i ADO b?ng C++
Cách ti?p c?n WebDAV
Ngôn ng?: VBScript, Visual Basic, Visual C
Exchange Server Phiên b?n: Exchange 2000 và Exchange 2003
B?n c?ng có th? s? d?ng WebDAV tương t?
cách ti?p c?n ADO. Các tài s?n và các thu?t toán là như nhau trong đó b?n
có th? thêm các giá tr? c?a
http://schemas.Microsoft.com/MAPI/proptag/x0e080003 t? t?t c? các thư m?c con trong m?t h?p thư. M?t l?i th? c?a vi?c s? d?ng
WebDAV thay v? c?a ADO là r?ng m? không ph?i ch?y trên máy tính
đó ch?y Exchange 2000 ho?c Exchange 2003.
S? d?ng m?u này, dán các
sau m? trong m?t t?p tin văn b?n m?i, và sau đó đ?t tên t?p tin Mailboxsize.vbs:
'This script logs on to a server that is running Exchange Server and
'displays the current number of bytes that are used in the user's
'mailbox.
' USAGE: cscript MailboxSize.vbs SERVERNAME MAILBOXNAME USERNAME PASSWORD
' SERVERNAME: Name of your Exchange Server
' MAILBOXNAME: Your alias (Note: depending on your environment, you may need to use the portion of your
' SMTP address left of the '@' symbol instead of your alias.
' USERNAME: Your domainname\username '
' PASSWORD: Your domain password
' This script is provided AS IS. It is intended as a SAMPLE only.
' Microsoft offers no warranty or support for this script.
' Use at your own risk.
' Get command line arguments.
Dim obArgs
Dim cArgs
Dim iSum
Set obArgs = WScript.Arguments
cArgs = obArgs.Count
Main
Sub Main()
Dim sUrl
Dim sMsg
On Error Resume Next
iSum = 0
' Check argument count.
If cArgs <> 4 Then
sMsg = "Usage: cscript MailboxSize.vbs "
sMsg = sMsg & "SERVERNAME MAILBOXNAME USERNAME PASSWORD"
WScript.Echo sMsg
Exit Sub
End If
sUrl = "http://" & obArgs.Item(0) & "/exchange/" & obArgs.Item(1) & "/NON_IPM_SUBTREE"
wscript.echo sUrl
RecurseFolder(sUrl)
WScript.Echo "Mailbox Size: " & iSum
End Sub
Public Sub RecurseFolder(sUrl)
Dim oXMLHttp
Dim oXMLDoc
Dim oXMLSizeNodes
Dim oXMLHREFNodes
Dim oXMLHasSubsNodes
Dim sQuery
Set oXMLHttp = CreateObject("Microsoft.xmlhttp")
If Err.Number <> 0 Then
WScript.Echo "Error Creating XML object"
WScript.Echo Err.Number & ": " & Err.Description
Set oXMLHttp = Nothing
End If
' Open DAV connection.
oXMLHttp.open "SEARCH", sUrl, False, obArgs.Item(2), obArgs.Item(3)
If Err.Number <> 0 Then
WScript.Echo "Error opening DAV connection"
WScript.Echo Err.Number & ": " & Err.Description
Set oXMLHttp = Nothing
End If
' Set up query.
sQuery = "<?xml version=""1.0""?>"
sQuery = sQuery & "<g:searchrequest xmlns:g=""DAV:"">"
sQuery = sQuery & "<g:sql>SELECT ""http://schemas.microsoft.com/"
sQuery = sQuery & "mapi/proptag/x0e080003"", ""DAV:hassubs"" FROM SCOPE "
sQuery = sQuery & "('SHALLOW TRAVERSAL OF """ & sUrl & """') "
sQuery = sQuery & "WHERE ""DAV:isfolder"" = true"
sQuery = sQuery & "</g:sql>"
sQuery = sQuery & "</g:searchrequest>"
' Set request headers.
oXMLHttp.setRequestHeader "Content-Type", "text/xml"
oXMLHttp.setRequestHeader "Translate", "f"
oXMLHttp.setRequestHeader "Depth", "0"
oXMLHttp.setRequestHeader "Content-Length", "" & Len(sQuery)
' Send request.
oXMLHttp.send sQuery
If Err.Number <> 0 Then
WScript.Echo "Error Sending Query"
WScript.Echo Err.Number & ": " & Err.Description
Set oXMLHttp = Nothing
End If
' Load XML.
Set oXMLDoc = oXMLHttp.responseXML
' Get the XML nodes that contain the individual sizes.
Set oXMLSizeNodes = oXMLDoc.getElementsByTagName("d:x0e080003")
' Get the XML nodes that contain the individual HREFs.
Set oXMLHREFNodes = oXMLDoc.getElementsByTagName("a:href")
' Get the XML nodes that contain the individual HasSubs.
Set oXMLHasSubsNodes = oXMLDoc.getElementsByTagName("a:hassubs")
' Loop through the nodes, and then add all of the sizes.
For i = 0 to oXMLSizeNodes.length - 1
WScript.Echo oXMLHREFNodes.Item(i).nodeTypedValue
WScript.Echo "Size: " & oXMLSizeNodes.Item(i).nodeTypedValue
iSum = iSum + oXMLSizeNodes.Item(i).nodeTypedValue
' If the folder has subfolders, call your recursive function to
' process subfolders.
If oXMLHasSubsNodes.Item(i).nodeTypedValue = True Then
RecurseFolder oXMLHREFNodes.Item(i).nodeTypedValue
End If
Next
' Clean up.
Set oXMLSizeNodes = Nothing
Set oXMLDoc = Nothing
Set oXMLHttp = Nothing
End Sub
Lưu ? Thêm vào phương pháp l?p tr?nh đư?c mô t? trong ph?n này, b?n có th? c?ng xu?t thông tin kích thư?c thư m?c vào m?t t?p tin văn b?n b?ng cách s? d?ng Exchange h? th?ng qu?n l?.
ID c?a bài: 320071 - L?n xem xét sau cùng: 27 Tháng Tám 2011 - Xem xét l?i: 2.0
Áp d?ng
- Microsoft Exchange Server 2003 Enterprise Edition
- Microsoft Exchange Server 2003 Standard Edition
- Microsoft Exchange 2000 Server Standard Edition
- Microsoft Exchange Server 5.5 Standard Edition
| kbhowto kbmt KB320071 KbMtvi |
Máy d?chQUAN TRỌNG: Bài vi?t này đư?c d?ch b?ng ph?n m?m d?ch máy c?a Microsoft ch? không ph?i do con ngư?i d?ch. Microsoft cung c?p các bài vi?t do con ngư?i d?ch và c? các bài vi?t do máy d?ch đ? b?n có th? truy c?p vào t?t c? các bài vi?t trong Cơ s? Ki?n th?c c?a chúng tôi b?ng ngôn ng? c?a b?n. Tuy nhiên, bài vi?t do máy d?ch không ph?i lúc nào c?ng hoàn h?o. Lo?i bài vi?t này có th? ch?a các sai sót v? t? v?ng, cú pháp ho?c ng? pháp, gi?ng như m?t ngư?i nư?c ngoài có th? m?c sai sót khi nói ngôn ng? c?a b?n. Microsoft không ch?u trách nhi?m v? b?t k? s? thi?u chính xác, sai sót ho?c thi?t h?i nào do vi?c d?ch sai n?i dung ho?c do ho?t đ?ng s? d?ng c?a khách hàng gây ra. Microsoft c?ng thư?ng xuyên c?p nh?t ph?n m?m d?ch máy này.
Nh?p chu?t vào đây đ? xem b?n ti?ng Anh c?a bài vi?t này:
320071
(http://support.microsoft.com/kb/320071/en-us/
)