Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
ADSI in VFP
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Titre:
Divers
Thread ID:
00314125
Message ID:
00314459
Vues:
22
>I have been doing some research into ADSI in VFP to try to create a simple "Add User" and "Add to Group" function without resorting to third party products or DLL's.
>
>I have searched the UT archives for similar messages and know that Ed Rauh and Paul Vlad Tatava have extensive knowledge in this area and that Paul has a library routine that performs a similar function.
>
>I attach some code that will work in VFP6.0 (once the ADSI SDK has been brought down and installed). It should be self explanatory. It gives inconsistent results in WinNT Workstation and WinNT Server.
>
>Anyone got any ideas about what is going on ?
>

I spent some more time with ASDI today and have come up with a solution. The following code illustrates how to list Users and their Groups and Groups and their assigned Users. It also allows you to create a new user and assign him/her to a Group.

Code follows
------------
Parameter pUser, pPassword, pGroup
set step off
clear
#DEFINE thiscomputer "yourdomain"
dom=GetObject("WinNT://"+thiscomputer)
on Error do ErrHand
lErr=0

if parameters()=3
	usr=dom.Create("user",pUser)
	if lErr=0
		usr.SetInfo()
	else
		usr=dom.GetObject("User",pUser)
	endi
	usr.SetPassword(pPassword)
	usr.SetInfo()
	grp=dom.GetObject("Group",pGroup)
	grp.Add("WinNT://"+thiscomputer+"/"+pUser)
	cancel
else
	lErr=1
	? "USERS"
	? "-----"
	for each usr in dom
		if usr.class="User"
			xxx=usr.Groups
			usrgrp=''
			for each grpx in xxx
				usrgrp=usrgrp+grpx.name+","
			endfor
			? usr.name+" ("+usrgrp+")"
		endi
	endfor
	?
	? "GROUPS"
	? "------"
	for each usr in dom
		uMemb=''
		if usr.class="Group"
			grp=dom.GetObject("Group",usr.Name)
			for each Member in grp.Members
				if !isnull(Member) and Member.Class="User"
					uMemb=uMemb+Member.name+","
				endi
			endfor
			? usr.name+" ("+uMemb+")"
		endi
	endfor
	cancel
endi
Procedure ErrHand
	if lErr=0
		lErr=1
		return
	endi
	? "Error Num:",error()," Message:",Message()
return
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform