#include <array.au3>
$group = _getusergroup("Administrator");返回用户所在的组,区分大小写
_ArrayDisplay($group, "Administrator所在的组")
$group = _getusergroup(@UserName);返回当前用户所在的组
_ArrayDisplay($group, @UserName & "所在的组")
Func _getusergroup($username)
Local $wbemFlagReturnImmediately = 0x10
Local $wbemFlagForwardOnly = 0x20
Local $colItems = ""
Local $strComputer = "localhost"
Local $Output = "", $user
Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_GroupUser", "WQL", _
$wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) Then
For $objItem In $colItems
$user = StringRegExp($objItem.PartComponent, 'Name=\"(.*?)\"', 3)
If $user[0] == $username Then
$temp = StringRegExp($objItem.GroupComponent, 'Name=\"(.*?)\"', 3)
$Output &= $temp[0] & "|"
EndIf
Next
Return StringSplit(StringTrimRight($Output, 1), "|")
Else
MsgBox(0, "WMI 输出", "没有在类 " & "Win32_GroupUser" & "中找到WMI对象")
EndIf
EndFunc ;==>_getusergroup
|