How to open the Property dialog of selected objects in Management Console?
Asked Answered
P

2

2

I am searching for the possibility to open default property dialogues for particular Windows objects, like:

  • the property dialogue for a particular service in services.msc
  • the property dialogue for a particular scheduled taks in taskschd.msc
  • etc.

I do not want to interact with that dialogues or change any of the properties. I just want to open them to give the user direct access to a single items properties (instead of opening the listings (by calling the *.msc executables) in which the user has to search the object again).

I have already partially copied the dialogues functions into own forms and code for other purposes, by the way, but I want to give the user the option to open the default ones and make any changes directly.

Now, I have found some hints but I am stuck as there is always some crucial information missing:

1. Using so-called SnapIns of MMC (Microsoft Management Console)

There is this relatively new answer which uses VB code but I have no clue how I could use the MMC Automation Object Model in C# .NET Framework.

Furthermore, there is no clean and easy example/explanation of how to simply call an existing .msc process/list/window by usage of the Microsoft.ManagementConsole. Instead, there are several horrifying complex tutorials how to implement SnapIns into C#.

To be clear here: What I want to do is to reference a dll, go through some list (if necessary) and just call the properties dialogue.

2. COM invoke of old API

There is this old answer where someone recommends using invoke on an outdated ITaskScheduler class which does not solve the general dialogue call but at least the one for scheduled tasks. Perhaps it is also possible to use something similar for services, etc. - but, again, there is no clear example or explanation of how to implement this approach.

Pinter answered 27/3, 2022 at 18:41 Comment(5)
The automation object model should work fine. Add the assembly with the model as a reference and go to town. There will be a lot of trial and error since those models tend to be a little weird, but it should definitely work.Lordly
Which assembly exactly?Pinter
Mmcndmgr.dll, and it's an unmanaged dll, I shouldn't have called it an assemblyLordly
There is no class or interface in the NODEMGRLib which let me create a referenced object like the user did in the delphi code. Actually, there is only 1 "useable" method called "EnableSnapInExtension" in MMCDocConfig but I have no idea which CLSIDs it expects. Rocket science.Pinter
Check the header files in the windows sdk for the clsids.Lordly
D
5

It's relatively simple.

For example:

Note: setting mmcApp.UserControl = 1; leaves the Console open, otherwise it would close.

using MMC20; 
// [...]

MMC20.Application mmcApp = new MMC20.Application();
mmcApp.UserControl = 1;
mmcApp.Load("services.msc");

var doc = mmcApp.Document;
var view = doc.ActiveView;
var node = view.ListItems.OfType<Node>().FirstOrDefault(n => n.Name == "Base Filtering Engine");

if (node != null) {
    view.Select(node);
    view.DisplaySelectionPropertySheet();
}

To enumerate the ListItems, use a standard loop or an extension method as shown above:

var nodes = view.ListItems;

foreach (MMC20.Node node in nodes) {
    Console.WriteLine(node.Name);
}
Default answered 27/3, 2022 at 21:45 Comment(5)
Thanks, I just found out the same after adding the COM object/reference to MMC20 (after the hint of @John V and googling how to use COM objects). Hurray!!!Pinter
I would indeed be superhappy if there would be something to navigate through the menu panel in the taskschd.msc to also call the propertysheet for a scheduled task ;)Pinter
In Task Manager, you have two Snap-Ins. The first one is a Selection Tree. You need to select a Node in the Tree Nodes, then use the second Snap-In object, get the current View, select one its Nodes and show the Property dialog. IIRC, the ScopeNamespace has the methods to navigate the Tree (e.g., Expand(), GetParent(), GetChild(), GetNext() etc.)Default
Note that I'm not exactly sure you can do this with MMC 2.0. I'll test it when I can.Default
Task Manager => Task Scheduler :)Default
L
1

Here's documentation on how to use the MMC SDK. It's a Win32 API, so you'll have to use COM, PInvoke, or other interop to use it.

https://learn.microsoft.com/en-us/previous-versions/windows/desktop/mmc/microsoft-management-console-start-page#developer-audience

The C++ examples are probably more informative than the VB ones. The .h files are part of the windows sdk so you should be able to find the clsid and other constants that you need in there: https://learn.microsoft.com/en-us/previous-versions/windows/desktop/mmc/using-c-with-the-mmc-2-0-automation-object-model

Lordly answered 27/3, 2022 at 20:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.