Title: Group Policy Attributes in the Active Directory
Question: How to get the sysvol information about a Group Policy object in the Active Directory
Answer:
Please look to the article - Creating windows accounts using ADSI - from Philip Jespersen here in this community for steps you need to do first to implement the ADSI Interface into the Delphi IDE.
************************************************************************************************
//I wrote a program to compare Group Policies. The following is an extract of my program code to get informations about a selected GPO
procedure Tfm_main.tv_gpoMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var knoten:ttreenode;
n,n2:integer;
obj: tGPM;
dom:Igpmdomain;
gpo:IGPMgpo;
guid:string;
begin
stuff before
guid:=lb_uniqueids.Items.Strings[lb_uniqueids.Items.IndexOf(knoten.Parent.Text)+(n2-n)];
try
// this part doesnt need ADSI, it uses to Interface of Microsofts GPMC
obj:=GPMGMTLib_TLb.TGPM.Create(self);
dom:=obj.GetDomain(knoten.Parent.Text,'',0);
gpo:=idispatch(dom.GetGPO(guid)) as igpmgpo;
l_gpo_createt_info.Caption:=datetostr(gpo.CreationTime);
l_gpo_modified_info.Caption:=datetostr(gpo.ModificationTime);
l_gpo_uniqueid_info.Caption:=gpo.ID;
l_gpo_guid.Caption:=guid;
l_gpo_adpath.Caption:=copy(gpo.Path,pos('},',gpo.path)+2,length(gpo.path));
finally
obj.Free;
end;
end;
// this procedure uses the ADSI Interface to open the sysvol folder in the explorer
procedure Tfm_main.ac_sysvolExecute(Sender: TObject);
var path:string;
dom : IAdscontainer;
obj : iads;
begin
Dom := mkGetObject('LDAP://'+l_gpo_adpath.caption) as IAdscontainer;
try
// the ADSI Interface doesnt know a class of GroupPolicyContainer, so I use the basic object iads
obj:=idispatch(dom.GetObject('','cn='+l_gpo_guid.caption)) as iads;
path:=obj.Get('gpcfilesyspath');
except
on exception do path:='';
end;
if length(path)=0 then
// shows a message in different languages
all_func.messages(10,gl_language)
else
// opens the correct sysvol folder
ShellExecute(Application.Handle,'OPEN',PCHar(path),nil,nil,sw_ShowNormal);
end;
*************************************************************************************************
// Thanks to Philip
// I renamed the original getobject function from Philip to avoid problems in the Delphi IDE because Delphi 2005 is providing a function with this name too
function mkGetObject(const Name : String): IDispatch;
var
Moniker : IMoniker;
Eaten : Integer;
BindContext : IBindCtx;
Dispatch : IDispatch;
begin
OleCheck(CreateBindCtx(0, BindContext));
OleCheck(MkParseDisplayName(BindContext, PWideChar(WideString(Name)), Eaten, Moniker));
OleCheck(Moniker.BindToObject(BindContext, NIL, IDispatch, Dispatch));
Result := Dispatch;
end;