WMI(Window Management Instrumentation)
: Windows에 대한 Microsoft의 주요 관리 기술입니다.
윈도우 서버를 관리하거나, 관리 응용프로그램을 만들 때 사용할 수 있다
윈도우 리소스 액세스, 구성, 관리, 모니터링 가능
* .net 2.0에서 사용하기위해서는 system.management.dll 이 필요함 3.0 부터 지원
이 기능을 이용하여 exchange 사서함의 상태정보 / 메일 사용량을 가져올 수 있다
StreamReader sr = new StreamReader(Request.InputStream);
string rtnValue = sr.ReadToEnd();
sr.Close();
sr = null;
WriteTextLog("rtnValue", rtnValue, "ezEmail");
pUserMBox = rtnValue.Split(';')[0].ToString();
userLegacyDN = rtnValue.Split(';')[1].ToString();
try
{
ManagementScope scope = new ManagementScope("\\\\" + pUserMBox + "\\root\\MicrosoftExchangeV2");
// 쿼리문에 많은 제약이 있음
ObjectQuery query = new ObjectQuery("select * from Exchange_Mailbox where legacyDN ='" + userLegacyDN + "' ");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
string pSize = string.Empty;
string pLimit = string.Empty;
string pBoxName = string.Empty;
foreach (ManagementObject mailbox in searcher.Get())
{
pSize = mailbox["Size"].ToString();
pLimit = System.Convert.ToString((StorageLimitInfo)(uint)(mailbox["StorageLimitInfo"]));
pBoxName = mailbox["MailboxDisplayName"].ToString();
}
string ret = "<DATA><SIZE>" + pSize + "</SIZE><LIMIT>" + pLimit + "</LIMIT><BOXNAME>" + pBoxName + "</BOXNAME></DATA>";
XmlDocument xmlRtn = new XmlDocument();
xmlRtn.LoadXml(ret);
Response.ContentType = "text/xml; charset=utf-8";
xmlRtn.Save(Response.OutputStream);
}
catch (Exception ex)
{
// Catch any exceptions. Any error codes from the SEARCH
// method request on the server will be caught here, also.
//Console.WriteLine(ex.Message);
WriteTextLog("Exception_getmailBoxsize", ex.Message + ", " + ex.StackTrace.ToString(), "ezEmail");
}
[Flags]
internal enum StorageLimitInfo
{
BELOWLIMIT = 1, ISSUEWARNING = 2, PROHIBITSEND = 4, NOCHECKING = 8, MAILBOXDISABLED = 16
}
[출처] WMI 이용하여 Exchange Mailbox 정보 가져오기|작성자 빡스



위로 가기


댓글을 달아 주세요
관리자만 볼 수 있는 댓글입니다.