llztt 发表于 2008-7-30 14:14:16

求枚举本机用户的方法??

NET USER 控制台法有些麻烦
找了一下WMI的资料
$objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
   $colItems = $objWMIService.ExecQuery("Select * from Win32_Account Where LocalAccount = True")
        For $objItem In $colItems
                ConsoleWrite($objItem.Description&@CRLF)
                ConsoleWrite($objItem.Domain&@CRLF)
                ConsoleWrite($objItem.InstallDate&@CRLF)
                ConsoleWrite($objItem.LocalAccount&@CRLF)
                ConsoleWrite("name--------------------"&$objItem.Name&@CRLF)
                ConsoleWrite($objItem.SID&@CRLF)
                ConsoleWrite($objItem.SIDType&@CRLF)
                ConsoleWrite($objItem.Status&@CRLF)
                ConsoleWrite("==========================================="&@CRLF)
        Next
这个把所有组所有用户还有些不知道什么东西都枚举出来了...不好把有用的用户数据剃出来..

请教还有其他办法没??

[ 本帖最后由 llztt 于 2008-7-30 14:26 编辑 ]

llztt 发表于 2008-7-30 14:25:05

论坛不能换行了,管理员检查有一下..
....已在AUTOIT自带工具里找大方法..
; 生成于 AutoIt Scriptomatic

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$Output=""
$Output = $Output & "Computer: " & $strComputer& @CRLF
$Output = $Output & "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_UserAccount", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $Output = $Output & "AccountType: " & $objItem.AccountType & @CRLF
      $Output = $Output & "Caption: " & $objItem.Caption & @CRLF
      $Output = $Output & "Description: " & $objItem.Description & @CRLF
      $Output = $Output & "Disabled: " & $objItem.Disabled & @CRLF
      $Output = $Output & "Domain: " & $objItem.Domain & @CRLF
      $Output = $Output & "FullName: " & $objItem.FullName & @CRLF
      $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF
      $Output = $Output & "LocalAccount: " & $objItem.LocalAccount & @CRLF
      $Output = $Output & "Lockout: " & $objItem.Lockout & @CRLF
      $Output = $Output & "Name: " & $objItem.Name & @CRLF
      $Output = $Output & "PasswordChangeable: " & $objItem.PasswordChangeable & @CRLF
      $Output = $Output & "PasswordExpires: " & $objItem.PasswordExpires & @CRLF
      $Output = $Output & "PasswordRequired: " & $objItem.PasswordRequired & @CRLF
      $Output = $Output & "SID: " & $objItem.SID & @CRLF
      $Output = $Output & "SIDType: " & $objItem.SIDType & @CRLF
      $Output = $Output & "Status: " & $objItem.Status & @CRLF
      if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
      $Output=""
   Next
Else
   Msgbox(0,"WMI 输出","No WMI Objects Found for class: " & "Win32_UserAccount" )
Endif


Func WMIDateStringToDate($dtmDate)

        Return (StringMid($dtmDate, 5, 2) & "/" & _
        StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
        & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc
页: [1]
查看完整版本: 求枚举本机用户的方法??