Solved

MMC Console Handle

Posted on 2004-04-05
8
446 Views
Last Modified: 2010-05-18
Hi,

I wrote a MMC Extentin snapin. It launches a worker thread which checks periodically the existance of a file. When the file is deleted some nodes from the result pane have to be removed.

So, I call SelectScopeItem(...) to set the focus to an item which will not be deleted and then I call DeleteItem(...) to remove the nodes.

This works fine under Win2K (MMC1.20) but not under XP (MMC2.0) where SelectScopeItem fails.

I assume, that the ConsoleHandle(IConsole) I use is not longer valid when using from a worker thread.

Has anyone experiences with such a constellation ??

How can console handles be used from a thread ?
Or:
How can Messages be posted into Notify() as if the user has selected "Delete" from the context menue.
And:
Does anyone know how to disable the "New Window from here" feature for a Snapin ??

THANX a lot

   TheGasmann

0
Comment
Question by:TheGasmann
  • 5
  • 2
8 Comments
 
LVL 3

Accepted Solution

by:
akalmani earned 500 total points
ID: 10755881
>>Does anyone know how to disable the "New Window from here" feature for a Snapin ??
There is a way for this. I do not know how to do it via the snap-in code. But another way which I used in my application.

Add only your snap-in to MMC and in the File->Options
Specify the title for the window. In the console mode use "User mode - Limited access, single window"

Save your file by closing the snap-in window as "MySnapIn.sys"

That's it. You need to distribute *.sys file along with your snap-in.
You need to save for Win2K and WinXP these *.sys files separately as the file format has been changed by Microsoft in respective OS.
0
 
LVL 3

Assisted Solution

by:akalmani
akalmani earned 500 total points
ID: 10755943
>>>How can console handles be used from a thread ?
Well you can make the console pointer as global variable and use it in worker thread.
I had used earlier in my snap-in as a global variable but of IConsole2 not IConsole.

In the class which derives from IComponent, there is an Initialize method which will be called. So make sure you store the IConsole2 * global variable in this function.

IConsole2 *g_pIConsole2;//Declare this in any one of the header files.

HRESULT CComponent::Initialize(/* [in] */ LPCONSOLE r_lpConsole)
{
  //Get the IConsole2 interface and store it
  r_lpConsole->QueryInterface(IID_IConsole2, (void **)&g_pIConsole2);
}

Make sure you release the interface in the end.
0
 
LVL 3

Assisted Solution

by:akalmani
akalmani earned 500 total points
ID: 10755985
>>>>How can Messages be posted into Notify() as if the user has selected "Delete" from the context menue ??

You also need a global pointer to IConsoleNameSpace2 * g_pIConsoleNameSpace2;

//In your CComponentData which implements IComponentData store the IConsoleNameSpace2* something like this
HRESULT CComponentData::Initialize(/* [in] */ LPUNKNOWN r_lpUnknown)
{
   //Get pointer to name space interface
    hResult = r_lpUnknown->QueryInterface(IID_IConsoleNameSpace,
                     (void **)&g_pIConsoleNameSpace2);
}

In your worker thread using this pointer you can directly delete the item.
g_pIConsoleNameSpace2->DeleteItem(ParentScopeItem, FALSE);


Make sure you release the interface in the end.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 3

Expert Comment

by:akalmani
ID: 10756006
0
 

Author Comment

by:TheGasmann
ID: 10756398
Well, the topic with the .sys file is new to me.
Quite a bit hard to distribute ...

But the other problems:
This is exactly what I do. But it doesn't work under XP (fine under 2000)
Especially when you select "new Window from here" and the new window shows nodes which are to be removed I get an Access violation :-(
0
 
LVL 3

Assisted Solution

by:akalmani
akalmani earned 500 total points
ID: 10984240
Even though the the asker does not like the answer, an answer was provided for 1 question.
0
 

Author Comment

by:TheGasmann
ID: 10984367
Sorry, I was on vacation and I forgot about this question.

So, the answer did not solve my problem, but as akalmani was the only one who answered I will give her/him the points for the effort she/he took.

Final comments:

* Sharing console handles with worker threads is NOT safe!
Calling Delete() from a worker thread might lead to a crash of the MMC :-(

* Some things got worse under XP (compared to Win2000).

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now