Directory Services

Example Code for Changing the Scope of a Group

The following code example changes the scope of a group.

WCHAR *pwszLDAPPath = L"LDAP://CN=mygroup,OU=myou,DC=Fabrikam,DC=com";
 
	HRESULT hr;
	IADsGroup * pGroup = NULL;
 
	// Initialize COM.
	CoInitialize(0);
 
	// Bind to the container passed. 
hr = ADsGetObject( pwszLDAPPath, IID_IADsGroup,(void **)&pGroup);
 
	if (SUCCEEDED(hr))
	{
		VARIANT vValue;
		BSTR	bsValue = SysAllocString(L"groupType");
		VariantInit(&vValue);
	// Set a new GroupType Value.
		vValue.vt = VT_I4;
		vValue.lVal = ADS_GROUP_TYPE_GLOBAL_GROUP ;
 
		hr = pGroup->Put(bsValue,vValue);
		hr = pGroup->SetInfo();
		pGroup->Release();
		pGroup= NULL;
		SysFreeString(bsValue);
}
 
	CoUninitialize();

The following code example changes the scope of a group.

Dim x as IADs
On Error GoTo CleanUp
Set x = GetObject("LDAP://CN=mygroup,OU=myou,DC=Fabrikam,DC=com")
x.Put "groupType", ADS_GROUP_TYPE_UNIVERSAL_GROUP|ADS_GROUP_TYPE_SECURITY_ENABLED
Exit Sub

CleanUp:
	MsgBox("An error has occurred.")
	x = Nothing