2010-03-09 2 views
0

Windows 시스템의 사용자 계정 변경 사항에 대한 로그 메시지를 구문 분석하고 있습니다. 변경 사항에 대해 사용자에게 알리고 싶으므로 Active Directory에서 개인 정보 (성, 이름, 전자 메일)를 검색해야합니다.VBScript 및 Active Directory를 사용하여 SID를 통해 사용자 전자 메일 찾기

는 이미 사용자 이름을 검색하는 방법을 발견하지만 그건 단지 WMI 아니라 ADSI를 통해 : 그것은 잘 작동

Function FindUser(Message) 
    Dim objWMIService 
    Dim strAccountRegex 
    Dim objRegex 
    Dim objMatch 
    Dim strComputer 
    Dim objUser 
    Dim objShell 


    strAccountRegex = "(\%\{[A-Z,0-9,\-]*\})" 
    strComputer = "." 

    Wscript.StdOut.writeLine "Querying WMI to retrieve user-data" 

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 
    Set objShell = WScript.CreateObject("WScript.Shell") 
    Set objRegex = new RegExp 
    objRegex.Pattern= strAccountRegex 
    for each objMatch in objRegex.Execute(Message) 
      REM Wscript.StdOut.writeLine "Found an Account ID: " & objMatch.value 
      Dim strSID 
      strSID=NormalizeSID(objMatch.value) 
      REM Wscript.Echo "SID after escaping: " & strSID 
      Set objUser = objWMIService.Get _ 
      ("Win32_SID.SID='" & strSID & "'") 
    next 
    FindUser=objUser.ReferencedDomainName & "\" & objUser.AccountName 
End Function 

,하지만 난 Active Directory에 대신 WMI를 통해 진행을 통해 그것을하고 싶습니다. 도와 주시겠습니까?

답변

0

확인. Active Directory를 통해이 작업을 수행 할 수있는 방법을 찾았습니다. 이 다른 사람에게 도움이 될 것입니다

REM Converts the SID into a from, that can be processed by WMI 
Function NormalizeSid(strSidToNormalize) 
    Dim regEx,strReplace 
    strReplace="" 
    ' Create regular expression. 
    Set regEx = New RegExp 
    regEx.Global = True 
    regEx.Pattern = "(%|{|})" 
    regEx.IgnoreCase = True 

    ' Make replacement. 
    NormalizeSid = regEx.Replace(strSidToNormalize, strReplace) 
End Function 

REM Searches for a SID the in the Message that was passed as argument 
REM SID returned will be of the form %{S-1-5-21-3968247570-3627839482-368725868-1110} 
REM NOTE: Neither WMI nor ADSI will accept this. Use NormalizeSid like in FindUser 
Function FindSidInMessage(Message) 
    Dim strAccountRegex 
    Dim objRegex 
    Dim objMatch 
    Dim strSID 

    strAccountRegex = "(\%\{S\-[,0-9,\-]*\})" 
    Set objRegex = new RegExp 
    objRegex.Pattern= strAccountRegex 

    for each objMatch in objRegex.Execute(Message) 
      REM Wscript.StdOut.writeLine "Found an Account ID: " & objMatch.value 
      strSID=objMatch.value 
    next 

    FindSidInMessage=strSID 
End Function 

REM Searches Directory for the User matching the SID passed as parameter 
Function FindUser(userSID) 
    Dim normalizedSID 
    Dim objUser 

    normalizedSID=NormalizeSid(userSID) 
    Wscript.Echo "SID after escaping: " & normalizedSID 

    Wscript.StdOut.writeLine "Querying AD to retrieve user-data" 
    Set objUser = GetObject("LDAP://<SID="& normalizedSID & ">") 
    FindUser=objUser.EmailAddress 
End Function 

희망 : 여기 compeleteness에 대한 는 코드입니다.

+0

어떻게하면됩니까? Eventlog를 내 보내야합니까? 그렇다면 어떻게 스크립트를 내보내기를 통해 실행할 수 있습니까? 미안, 나는 프로그래머가 아니야. 나는 이벤트 내부의 SID를 사용자와 일치 시키려고한다. –

+0

다음을 사용합니다 : http://www.sql-und-xml.de/freeware-tools/index.html#evt-Watch 불행히도 독일어 개발자가 작성했지만 Google 번역을 사용하면 운이 좋을 것입니다;) – er4z0r

관련 문제