Implementing DLL
- From: Mathias Riechert <MathiasRiechert@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 20 Sep 2007 05:06:01 -0700
The problem is an implementation of a extension for the Active Directory
users and computers snap in
in the microsoft management console.
Language: c#
Platform Windows XP
Only the Computers Object is to be extended.
[SnapInSettings("{{FE2EE5B3-8BEE-4729-B959-50A69C423FA2}}",
DisplayName = "- Computer Info",
Description = "Adds a Property Page to Computer
Management")]
[ExtendsNodeType("{bf967a86-0de6-11d0-a285-00aa003049e2}")]//
computer in ad users and computers
I can't use the register option of the Visual Studio, because I have
to install the extension on all computers in the network by a batch
job.
So I tried copying the DLL in die Windows\system32 folder and used the
tool regasm "C:\windows\system32\propext.dll"
Here I'm getting the message that it registered successfully.
But I can't find the extension in the MMC under computers.
so I tried installutil.exe, which sais:
Ausnahmefehler beim Suchen der Installer in der Assembly
C:\WINDOWS\assembly\GAC
_MSIL\RuagProp\1.2.7.0__f48f104487524ced\RuagProp.dll.
System.Reflection.ReflectionTypeLoadException: Mindestens ein Typ in der
Assembl
y kann nicht geladen werden. Rufen Sie die LoaderExceptions-Eigenschaft ab,
wenn
Sie weitere Informationen benötigen.
Die Installation von
C:\WINDOWS\assembly\GAC_MSIL\RuagProp\1.2.7.0__f48f10448752
4ced\RuagProp.dll wird abgebrochen.
Während der Installationsphase ist eine Ausnahme aufgetreten.
System.InvalidOperationException: Die Installertypen in der Assembly
C:\WINDOWS\
assembly\GAC_MSIL\RuagProp\1.2.7.0__f48f104487524ced\RuagProp.dll können
nicht a
bgefragt werden.
Die interne Ausnahme System.Reflection.ReflectionTypeLoadException wurde mit
fol
gender Fehlermeldung ausgelöst: Mindestens ein Typ in der Assembly kann
nicht ge
laden werden. Rufen Sie die LoaderExceptions-Eigenschaft ab, wenn Sie
weitere In
formationen benötigen..
meaning: a type in the assembly is missing.
So I tried using the autoregister function of VS2005. But here i get the
error:
Fehler 10 Die C:\1\bin\Debug\RuagProp.dll-Assembly kann nicht registriert
werden. Die Datei oder Assembly Microsoft.ManagementConsole, Version=3.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35 oder eine Abhängigkeit davon
wurde nicht gefunden. Das System kann die angegebene Datei nicht finden.
meaning: the assembly can't be registered. The File or Assembly
Microsoft.ManagementConsole ... or a Dependency is missing. Can't find the
file.
So I reinstalled MMC3.0, Windows SDK, copied the
microsoft.managementconsole.dll and MMCFxCommon.dll in the folder of the
Project, deleted the reference for managementconsole.dll and reloadet the one
from the project folder.
still i can't register the project.
Am I missing some steps in registering or why the Snap In is not showing?
Here is documented how to add a Property *** "AD Users and Computers Snap
In" in the MMC 3.0: http://msdn2.microsoft.com/en-us/library/ms692751.aspx
My Code is also based on this example.
I already had this Extension showing in the user-node of the "AD Users and
Computers Snap In" last year.
I thought, I just have to change the ID of the extended node into the
computer object of this snap in. (took it from here:
http://msdn2.microsoft.com/en-us/library/ms680987.aspx), but that doesn't
work. I could not find anything how to solve this problem.
I also generated a new GUID and changed it.
But strangehow I can't register the changed one.
I also checked if it is a strong name, here the sn return:
C:\Program Files\Microsoft Visual Studio 8\VC>sn -v
C:\1\bin\debug\ruagprop.dll
Microsoft (R) .NET Framework-Dienstprogramm für starke Namen
Version 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
The Assembly "C:\1\bin\debug\ruagprop.dll" is valid.
--> strong name
(I included a Key in the Compiler)
So that is not the problem.
Here is the Code of the Extension.cs :
Code Snippet
//=======================================================================================
//
// This source code is only intended as a supplement to existing Microsoft
documentation.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
// PURPOSE.
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
//
//=======================================================================================
//
// Purpose:
// Shows how to create an ExtensionProperty*** for the Computer Management
snap-in .
//
//=======================================================================================
//
// Description:
// Uses the ExtendsNodeType attribute and the Guid of the ‘Computer
Management’
// snap-in root node to create a ExtensionProperty***. Uses the shared data
// features to get some data from the primary and use it in the Extension
***.
//
//=======================================================================================
using System;
using System.Text;
using System.Configuration.Install;
using System.ComponentModel;
using System.Security.Permissions;
using System.Windows.Forms;
using Microsoft.ManagementConsole;
using Microsoft.ManagementConsole.Advanced;
[assembly: PermissionSetAttribute(SecurityAction.RequestMinimum,
Unrestricted = true)]
namespace Microsoft.ManagementConsole.Samples
{
/// <summary>
/// RunInstaller attribute - Allows the .Net framework InstallUtil.exe to
install the assembly.
/// SnapInInstaller class - Installs snap-in for MMC.
/// </summary>
[RunInstaller(true)]
public class InstallUtilSupport : SnapInInstaller
{
}
/// <summary>
/// Property *** extension for the root node of Computer Management snap-in.
/// </summary>
[SnapInSettings("{{FE2EE5B3-8BEE-4729-B959-50A69C423FA2}}",
DisplayName = "- RUAG Computer Info",
Description = "Adds a Property Page to Computer Management")]
[ExtendsNodeType("{bf967a86-0de6-11d0-a285-00aa003049e2}")]//computer ind ad
users and computers
public class RUAGProp : PropertySheetExtension
{
private SharedDataItem sharedDataItem;
/// <summary>
/// Extension class to extend the Computer Management snap-in property ***
/// </summary>
public RUAGProp()
{
// In order to receive published data from the primary snap-in, MMC needs to
know which
// data items the extension is interested in.
// sharedDataItem = new SharedDataItem("lpIDataObject");
// sharedDataItem = new SharedDataItem("DSOBJECT");
sharedDataItem = new SharedDataItem(@"DSOBJECTNAMES");
this.SharedData.Add(sharedDataItem);
// sharedDataItem = new SharedDataItem("DSOBJECTNAMES");
// this.SharedData.Add(sharedDataItem);
}
/// <summary>
/// Initialization notification.
/// </summary>
protected override void OnInitialize()
{
}
/// <summary>
/// Virtual method that is called to get the extension pages.
/// </summary>
/// <param name="propertyPageCollection">Page collection.</param>
protected override void OnAddPropertyPages(PropertyPageCollection
propertyPageCollection)
{
const int OFFSET_SELECTED_OBJECTS_COUNT = 16;
MarshalBuffer buffer = new MarshalBuffer(sharedDataItem.GetData());
int selectedCount = buffer.ReadInt(OFFSET_SELECTED_OBJECTS_COUNT);
//Propertypage should not be displayed if multiple objects are selected.
if (selectedCount == 1)
{
// add extension page.
// UserPropertyPage is the class inherited from PropertyPage and is called
MachinePropertyPage in the SDK sample.
MachinePropertyPage machinePropertyPage = new
MachinePropertyPage(sharedDataItem);
propertyPageCollection.Add(machinePropertyPage);
}
}
} //class
public class MarshalBuffer
{
byte[] _buffer = null;
public MarshalBuffer(uint size)
{
_buffer = new byte[size];
}
public MarshalBuffer(byte[] buffer)
{
_buffer = buffer;
}
public int ReadInt(uint offset)
{
return BitConverter.ToInt32(_buffer, (int)offset);
}
public long ReadChar(uint offset)
{
return BitConverter.ToChar(_buffer, (int)offset);
}
public string ReadString(uint offset)
{
StringBuilder str = new StringBuilder();
uint i = 0;
while (this.ReadChar(offset + i) != (char)0)
{
str.Append((char)this.ReadChar(offset + i));
i = i + 2;
}
return str.ToString();
}
}
} // namespace
.
- Prev by Date: Problem with faking a progress bar / threading.
- Next by Date: Re: Problem with faking a progress bar / threading.
- Previous by thread: Problem with faking a progress bar / threading.
- Next by thread: copy constructor
- Index(es):