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("ChkUs erGroup.Ch kUserGrp")
if MyCompute.InGroup("me","IT DEPT") = 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?
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("ChkUs
if MyCompute.InGroup("me","IT
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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! :)
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 :)
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!
ASKER
ADSI solves the problem.
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.