Hix
Hix

Reputation: 39

Get information about the currently extended GPO

We are currently developing an MMC SnapIn Extension, that extends multiple group policy objects (GPOs), like you can see it in that image below:

Group Policy Management Editor - Extended

Thecnology is MMC 3.0, .NET 3.5, C#, VS2013. The extension is available on all GPOs.

The main class of the extension looks like this (in an anonimized way)

[SnapInSettings("{3B6F64DC-4572-4A64-957A-E8A9E2FEBD54}", DisplayName = "DisplayName", Description = "MMC Snap-In")]
[ExtendsNodeType("{8FC0B739-A0E1-11D1-A7D3-0000F87571E3}")]
[ExtendsNodeType("{D37CB93E-0DDC-4204-AA04-C3D70B01A7D8}")]
public class ExtensionSnapIn : NamespaceExtension
{
}

Everything works fine except I cannot determine which GPO is the parent of the currently opened extension. I would like to know this because I have to write into the registry to the following path: HKLM\Software\Company\Product\Client Group Policy\[GPOID]\

I would like to have this ID dynamically: I'm looking look for the highlighted GUID

I have tried a lot of things with no result at all:

If a node does not have this attribute, it cannot be registered as an extensible node.

Sample:

//private const string shdata = "CCF_SCE_GPT_UNKNOWN";
//private const string shdata = "CCF_SNAPIN_CLASSID";
//private const string shdata = "CCF_DISPLAY_NAME";
//private const string shdata = "CCF_NODETYPE";
//private const string shdata = "CCF_SZNODETYPE";
//private const string shdata = "CCF_SNAPIN_CLASSID";
//private const string shdata = "CCF_DISPLAY_NAME";
//private const string shdata = "CFSTR_DSOBJECTNAMES";
private const string shdata = "CCF_SCE_GPT_UNKNOWN";

public ExtensionSnapIn()
{
    this.PrimaryNode.SharedData.Add(new SharedDataItem(shdata));
}

protected override void OnInitialize()
{
    SharedDataItem sharedDataItem = this.PrimaryNode.SharedData.GetItem(shdata);
}

I'm always getting an exception. For CCF_NODETYPE, CCF_SZNODETYPE, CCF_SNAPIN_CLASSID, CCF_DISPLAY_NAME I'm getting this:

The following clipboard format is reserved for use by MMC: CCF_DISPLAY_NAME. Specify another clipboard format.

The rest of the clipboard formats just give a PrimarySnapInDataException with this stack trace:

at Microsoft.ManagementConsole.SharedDataItem.GetData() at Balabit.SyslogNgAgent.MMC.ExtensionSnapIn.OnInitialize() in c:\Source\Bergholz\Client\Client.Product\Main\src\MMC\ExtensionSnapIn.cs:line 65 at Microsoft.ManagementConsole.Advanced.NamespaceExtension.ProcessNotification(Notification notification) at Microsoft.ManagementConsole.Internal.SnapInClient.Microsoft.ManagementConsole.Internal.IMessageClient.ProcessNotification(Notification notification) at Microsoft.ManagementConsole.Executive.SnapInInitializationOperation.OnStart() at Microsoft.ManagementConsole.Executive.RunningOperationsTable.EnqueueOperation(Operation operation) at Microsoft.ManagementConsole.Executive.NamespaceExtensionComponentData.GetScopeNodeForExpand(IDataObject dataObject, IntPtr hScopeItem) at Microsoft.ManagementConsole.Executive.ComponentData.OnExpand(IDataObject dataObject, Boolean isExpanding, IntPtr hScopeItem) at Microsoft.ManagementConsole.Executive.ExpandMmcNotification.OnNotify(IntPtr dataObject, IntPtr arg, IntPtr param) at Microsoft.ManagementConsole.Executive.MmcNotifyTarget.Notify(IntPtr dataObject, NotificationType eventType, IntPtr arg, IntPtr param)

I have googled this problem for days, and I have read tons of articles about MMC Extension SnapIns, and GPO, but I have not yet found any usable solutions for my problem.

Thanks for your help in advance.

Upvotes: 3

Views: 255

Answers (0)

Related Questions