I'm tring to work on this function but I'm getting a syntax error (0x80041002). Here is what I pieced together so far:
Function IsUserAdmin(strUser)
Set objWMI = GetObject("WinMgmts:\\" & strComputerName & "\root\cimv2")
For Each objItem In objWMI.ExecQuery("ASSOCIATORS OF {Win32_Group.Domain='BUILTIN',Name='Administrators'} Where AssocClass=Win32_GroupUser")
On Error Resume Next
If InStr(1,objItem.Caption,strUser,vbTextCompare) Then
IsUserAdmin = True
End If
Next
Set objWMI = Nothing
End Function
I get the syntax error at the "For" statement.
Any suggestions?
Function IsUserAdmin(strUser)
Set objWMI = GetObject("WinMgmts:\\" & strComputerName & "\root\cimv2")
For Each objItem In objWMI.ExecQuery("ASSOCIATORS OF {Win32_Group.Domain='BUILTIN',Name='Administrators'} Where AssocClass=Win32_GroupUser")
On Error Resume Next
If InStr(1,objItem.Caption,strUser,vbTextCompare) Then
IsUserAdmin = True
End If
Next
Set objWMI = Nothing
End Function
I get the syntax error at the "For" statement.
Any suggestions?