-1

I have created a windows service which should open and run a ABC.exe application. I know it is a bad practice to do this dont downvote for this reason coz i dont have any other option at the moment. i have done research about this a lot and found out a work around as making it interactive.i used this link: https://code.msdn.microsoft.com/windowsapps/CSCreateProcessAsUserFromSe-b682134e but the problem i am facing right now is user have to manually set Local System Account and check the "Allow Service to interact with Desktop" box. all i want to do right now is set it checked by default at the time of installation. so when user installs the service it should be already checked and the service should be in the running state(dont have to manually start the service-i am done with this part). i have seen some similar post here but they all show way to start the service from external app like creating another console app and using system.management.managementobject. i want to know if there is any way to add some code in the service itself and where to add it? ps.: i am creating this service for windows vista+ systems.

please help as i am stuck on this problem for quite a while. Thanks in advance.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
uday vichare
  • 61
  • 12

1 Answers1

0

What i suggest you do is modify the value directly in registry

In the installer class, override the OnCommitted(System.Collections.IDictionary savedState) method.

In that method, modify the registry key that ensures this setting, like so:

protected override void OnCommitted(System.Collections.IDictionary savedState)
{
  base.OnCommitted(savedState);
  string regKey = "SYSTEM\\CurrentControlSet\\Services\\MyServiceName";
  var key = Registry.LocalMachine.OpenSubKey(regKey, RegistryKeyPermissionCheck.ReadWriteSubTree)
          ?? Registry.LocalMachine.CreateSubKey(regKey, RegistryKeyPermissionCheck.ReadWriteSubTree);

 // might need to check the result, should be hex 110 or Decimal 272
 key.SetValue("Type", 272, RegistryValueKind.DWord); 
}
zaitsman
  • 8,984
  • 6
  • 47
  • 79