Link to home
Start Free TrialLog in
Avatar of dlisk
dlisk

asked on

Automation error Invalid syntax

I tried the other methods mentioned to get a user's groups within NT but couldn't get them to work in my intranet so I wrote this simple VB and created it as a DLL:-

Option Explicit

Public Function InGroup(UserName As Variant, UserGroup As Variant) As Boolean
Dim UserObj, GroupObj As Object
Dim seaStr As String
seaStr = "WinNT://XXX/" & UserName
Set UserObj = GetObject(seaStr)

InGroup = False
For Each GroupObj In UserObj.Groups
    If UCase(GroupObj.Name) = UCase(UserGroup) Then
        InGroup = True
        GoTo InGroup_Exit
    End If
Next

InGroup_Exit:
    Set UserObj = Nothing
    Set GroupObj = Nothing

End Function

This works when called from a VB program but fails on the line with the "if" statement below with:-

"ChkUserGroup error '800401e4'

Automation error Invalid syntax "

when used (via interdev) in a .ASP in IE5 thus:-

Set MyCompute = server.createobject("ChkUserGroup.ChkUserGrp")

if MyCompute.InGroup("me","ITDEPT") = false  Then
Response.Write "no-no"
else Response.Write "OK"
end if

I have tried an "on error" but this always results in "OK" regardless.
The autocomplete recognises the parameters for the method so I presume the DLL is OK - it works in VB as I said.
This may be related to variants as it failed with another error message before when I used string parameters.
Sorry if I'm being thick but this is the 1st time I've tried this.

Ideas anyone?
ASKER CERTIFIED SOLUTION
Avatar of Dave_Greene
Dave_Greene

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If there is a way to iterate through the Groups collection without using the For Each .. syntax, I would try that.  For Each can fail in Active X components (for no good reason.)

Don't know if this syntax is possible,

For i = 1 to UserObj.Groups.Count
  Set GroupObj = UserObj.Groups.Item(i)
  ...
  Set GroupObj = Nothing
Next i

Try it anyway, and if it doesn't work at least you've ruled that possibility out.
Avatar of dlisk
dlisk

ASKER

Gents, many thanks for your swift responses. Am much impressed with this resource. Still trying to fix this thang as the first answer appears to be no different in IE5 and the 2 combined won't work in VB. Am still trying to iterate through the properties of the user group objects (if I knew what they were) and trying to avoid the "FOR EACH". I WILL WIN! I owe yous a pint for your assistance. Ta again.
Did you get this one worked out?  I'm ready for that pint!  :)
Avatar of dlisk

ASKER

Hi Dave, your fellow Dave here! I'm still working on it; the latest is that the VB code I was using that worked on my PC as a VB program didn't work on someone else's - it came up with the same error (invalid syntax) on the GETOBJECT statement - which can't be used directly in IE, I believe. Is this because it could be to do with privileges or a different PC? Don't spend too much time on this but I thank you greatly for your concern and efforts.
Ok, keep us posted, curious on this one  :)
Avatar of dlisk

ASKER

And the answer was... download and instal ADSI from Microsoft and you can call the original getobject from the ASP VBScript. Simple when you know how!
Avatar of dlisk

ASKER

ADSI solves the problem.