Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. interacting with windows service

interacting with windows service

Scheduled Pinned Locked Moved C#
tutorialquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chesnokov Yuriy
    wrote on last edited by
    #1

    Is there a way to retrieve the data from the service using ServiceController? 1) I've got exception while trying to execute custom commands on the service 2) How to obtain the return code after the external command executed? The service is LocalSystem one. I start and stop it from external console application without problems. But once I add external commands after the service has been started sc.ExecuteCommand((int)Commands.Cmnd1); the exception is being thrown that the service can not be manipulated.

    Чесноков

    S L 2 Replies Last reply
    0
    • C Chesnokov Yuriy

      Is there a way to retrieve the data from the service using ServiceController? 1) I've got exception while trying to execute custom commands on the service 2) How to obtain the return code after the external command executed? The service is LocalSystem one. I start and stop it from external console application without problems. But once I add external commands after the service has been started sc.ExecuteCommand((int)Commands.Cmnd1); the exception is being thrown that the service can not be manipulated.

      Чесноков

      S Offline
      S Offline
      spiritboy
      wrote on last edited by
      #2

      would you specify the type of exception? maybe you do not have sufficient privileges to execute the commands, for gaining privileged u should add a manifest file to your project

      C 1 Reply Last reply
      0
      • C Chesnokov Yuriy

        Is there a way to retrieve the data from the service using ServiceController? 1) I've got exception while trying to execute custom commands on the service 2) How to obtain the return code after the external command executed? The service is LocalSystem one. I start and stop it from external console application without problems. But once I add external commands after the service has been started sc.ExecuteCommand((int)Commands.Cmnd1); the exception is being thrown that the service can not be manipulated.

        Чесноков

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3
        1. You need to ensure the custom command code is between 128 and 256.Values below 128 correspond to system-reserved values and values up 256 are restricted. 2) It seems that there's no standart framework designed to send and receive data to windows service and back.It's only a few information on the internet for this problem but I believe that it shouldn't be difficult to implement communication with a service based on sockets or named pipes. [EDIT] You could also set AutoLog property of ServiceBase class to true to gather information about custom commands execution from the eventlog.

        Life is a stage and we are all actors!

        modified on Tuesday, October 27, 2009 7:07 AM

        C 1 Reply Last reply
        0
        • L Lost User
          1. You need to ensure the custom command code is between 128 and 256.Values below 128 correspond to system-reserved values and values up 256 are restricted. 2) It seems that there's no standart framework designed to send and receive data to windows service and back.It's only a few information on the internet for this problem but I believe that it shouldn't be difficult to implement communication with a service based on sockets or named pipes. [EDIT] You could also set AutoLog property of ServiceBase class to true to gather information about custom commands execution from the eventlog.

          Life is a stage and we are all actors!

          modified on Tuesday, October 27, 2009 7:07 AM

          C Offline
          C Offline
          Chesnokov Yuriy
          wrote on last edited by
          #4
          1. They were starting from 0 actually (0,1,2, ...) 2) I needed custom commands to get the feedback from the service, the same as you call ordinary function and it returns some error code. Otherwise I will have to implement such other communication Looking into logs would sute only for visual inspection.

          Чесноков

          L 1 Reply Last reply
          0
          • S spiritboy

            would you specify the type of exception? maybe you do not have sufficient privileges to execute the commands, for gaining privileged u should add a manifest file to your project

            C Offline
            C Offline
            Chesnokov Yuriy
            wrote on last edited by
            #5

            System.InvalidOperationException

            Чесноков

            1 Reply Last reply
            0
            • C Chesnokov Yuriy
              1. They were starting from 0 actually (0,1,2, ...) 2) I needed custom commands to get the feedback from the service, the same as you call ordinary function and it returns some error code. Otherwise I will have to implement such other communication Looking into logs would sute only for visual inspection.

              Чесноков

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              As it's mentioned in the documentation here custom command codes should be only between 128 and 256:

              The only values for a custom command that you can define in your application or use in OnCustomCommand are those between 128 and 256. Integers below 128 correspond to system-reserved values.

              Just take a look to this sample that demonstrates this behavior. I haven't found almost nothing about sending and receiving that from service but after analyzing some service based apps like SQL Server Db engine I suppose they it uses TCP socket on port 1433 and named pipes to serve the clients.

              Life is a stage and we are all actors!

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups