how to open a service properties dialog
Asked Answered
C

3

7

I would like to add a button to my application ( frontend to a service) that will open the service properties dialog (like in services mmc snapin ) for my service.

There are numerous examples to open file properties, but that is not what i want. i dont know where to start.

Concepcionconcept answered 26/11, 2012 at 13:12 Comment(5)
I'm not sure if this is possible. You could use the ServiceController class and build your own dialog quite easilly.Kronick
i already use the service control manager api to do the basic things like installing, starting, stoping, uninstalling... however i want to add the properties dialog so that the user can customize other properties for the service like recovery optionsConcepcionconcept
I see. I cannot find a way to do this using the API in System.serviceProcess. The answer in the following question #6365200 shows an approach on how to handle the recovery yourself.Kronick
i am positive that there must be a way that is similar to the file properties dialog(using ShellExecute). for example: how do other processes open the display properties dialog or other similar dialogs that are often associated with the shell?Concepcionconcept
@twittfort, you can see my example to do thatCarruthers
C
0

Today I'm found that this is possible!

This is code on Delphi, which uses MMC 2.0 Automation Object Model

var
  objMMC: OleVariant;

procedure ShowSvcProperties(const ASvcName: string);
var
  objView, objList, objItem: OleVariant;
  SvcEnum: IEnumVariant;
  Value: UInt32;
  sName: string;
begin
  objMMC := CreateOleObject('MMC20.Application');
  objMMC.Load('services.msc');
  objView := objMMC.Document.ActiveView;
  objList := objView.ListItems;
  SvcEnum := IUnknown(objList._NewEnum) as IEnumVariant;
  while SvcEnum.Next(1, objItem, Value) = S_OK do
  try
    sName := objItem.Name;
    if SameText(sName, ASvcName) then begin
      objView.Select(objItem);
      objView.DisplaySelectionPropertySheet;
      Break;
    end;
  finally
    VariantClear(objItem);
  end;
end;

And now to show service properties dialog just call ShowSvcProperties('Plug and Play');

Carruthers answered 15/3, 2020 at 21:11 Comment(1)
S
6

Based off of the services.msc, the page comes from filemgmt.dll and is called ServicePageGeneral. While the COM components are registered, I cannot find any documentation for the CLSID in question, nor for any of the other strings present in filemgmt.dll.

This does not rule out the possibility that there exists an established API, or a command line option to show the dialog, but I certainly can't find one.

Further substantiating the case that the dialog is not reusable, Process Explorer and SQL Server Configuration Manager both re-implement the dialog, rather than showing the services.msc version.

Related: How do I open properties box for individual services from command line or link?

Springs answered 15/11, 2014 at 19:33 Comment(3)
ouch. the effort needed to find weather what i want to do is possible seems monolithic. making my own could take less.Concepcionconcept
@LawrenceWard, I tend to agree.Springs
@Mitch, this is possible! You can see my answerCarruthers
M
1

You should develop you custom "Service Console", with .NET and WMI classes you can query the service list in the computer, get the actual status, aditionally you should execute Windows Commands from you application to Start, Stop Services.

Meritorious answered 20/11, 2014 at 23:34 Comment(3)
i really dont want to duplicate what the operating system has already done. any administrator already knows how to use this dialog.Concepcionconcept
Lawrence, you still need the dialog two years after asking the question? :)Hyperbolic
I do, it would realy make a nifty aditional feature to my offering. At the time I decided that the effort required to make my own was too much and the feature has never been included.Concepcionconcept
C
0

Today I'm found that this is possible!

This is code on Delphi, which uses MMC 2.0 Automation Object Model

var
  objMMC: OleVariant;

procedure ShowSvcProperties(const ASvcName: string);
var
  objView, objList, objItem: OleVariant;
  SvcEnum: IEnumVariant;
  Value: UInt32;
  sName: string;
begin
  objMMC := CreateOleObject('MMC20.Application');
  objMMC.Load('services.msc');
  objView := objMMC.Document.ActiveView;
  objList := objView.ListItems;
  SvcEnum := IUnknown(objList._NewEnum) as IEnumVariant;
  while SvcEnum.Next(1, objItem, Value) = S_OK do
  try
    sName := objItem.Name;
    if SameText(sName, ASvcName) then begin
      objView.Select(objItem);
      objView.DisplaySelectionPropertySheet;
      Break;
    end;
  finally
    VariantClear(objItem);
  end;
end;

And now to show service properties dialog just call ShowSvcProperties('Plug and Play');

Carruthers answered 15/3, 2020 at 21:11 Comment(1)

© 2022 - 2024 — McMap. All rights reserved.