Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

VBScript to check if a user is a group member runs on Windows 7 & 8 but not on XP

$
0
0

Hi all,

I have a VBS function (IsMember) to check whether a user is a member of a group or not - The domain, username and group name are passed in when the function is called... My dilemma is that it works fine in Windows 7/8/Server 2008 R2/2012 R2 etc. but fails when run on XP/Server 2003 with the fairly generic error of 0x80005008 at source (null). I'm wondering if it could be something syntax related with my query? Or if there is perhaps a component I am trying to reference that doesn't exist in XP?

Here's the function;

IsMember "domain", "userDN", "group"

Function IsMember(Domain, User, Group)
	Dim oConnect, oRecordSet, oGroup

	Set oConnect = CreateObject("ADODB.Connection")
	oConnect.Open = "Provider=ADsDSOObject"

	Set oRecordSet = oConnect.Execute("SELECT AdsPath FROM 'LDAP://" & Domain & "' WHERE cn='" & Group & "'")

	Set oGroup = GetObject(oRecordSet("AdsPath"))
	If (oGroup.IsMember("LDAP://" & User)) Then
		IsMember = True
	Else
		IsMember = False
	End If

	oConnect.Close

	Set oConnect = Nothing
	Set oGroup = Nothing
	Set oRecordSet = Nothing
End Function

If anyone has any suggestions or ideas as to where I might be going wrong I'd be very grateful.

James






Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>