2

I want to start "services.msc" programmatically and select a services by the name. I can show the window but in this case no service is selected:

var proc = new Process();
proc.StartInfo.FileName = "services.msc";
//proc.StartInfo.Arguments = "MyServiceName";
proc.Start();

Is there an argument that I can specify to select a service?

Andark
  • 400
  • 4
  • 16
  • Perhaps look into the _[Windows Automation APIs](https://msdn.microsoft.com/en-us/library/windows/desktop/ff486375(v=vs.85).aspx)_ –  Jul 22 '15 at 04:36
  • I think that it's not possible and that the best way is to inform your users in an other way (popup/alert/log/tell them). – silver Jul 22 '15 at 06:28

1 Answers1

1

I have been having this problem (and then some) but was not convinced that it could not be done without rolling out a custom solution (Related: how to open a service properties dialog).

I ended up using AutoIt (https://www.autoitscript.com/site/autoit/downloads/). I first used AutoIt Window Info to get the control details. Then I added a reference to the AutoItX3.Assembly.dll and added the following code:

AutoItX.Run(string.Format("{0} \"{1}\"", fileName, args), AppDomain.CurrentDomain.BaseDirectory);
AutoItX.WinWaitActive("Services");
int result = AutoItX.ControlFocus("Services", "Services (Local)", "[CLASS:MMCOCXViewWindow; INSTANCE:1]");

if (result == 1)
{
    AutoItX.ControlSend("Services", "Services (Local)", "[CLASS:SysHeader32; INSTANCE:1]", "{TAB}");
    AutoItX.Send("MyService");
}

Since I didn't want to register the dll (so that I can distribute the files) I added the AutoItX3.Assembly.dll, AutoItX3.Assembly.xml, AutoItX3.dll, and AutoItX3_64.dll to my solution.

It works adequately. In my case I also wanted to pop up the properties, so I added an extra {ENTER} afterwards.

Community
  • 1
  • 1
Balah
  • 2,530
  • 2
  • 16
  • 24