因为是远程调用自己写的带自定义命令处理方法的windows服务,需要帐号控制,所以不用ServiceProcess命名空间而是使用WMI,
而用WMI的ManageObject通过属性字符串值访问windows服务的时候,可以用 ManageObject的的实例去InvokeMethod("StartService",params)启动服务,InvokeMethod("StopService",params)停止服务,那用户自定义命令Command对应的是什么属性值呢?
比如调用对应的128号自定义命令
InvokeMethod("Command",objects[]{128})
InvokeMethod("ExecuteCommand",objects[]{128})
都不对,说没有类有这个方法.那应该传什么名字呢?

解决方案 »

  1.   

    InvokeMethod( "UserControlService", new object[]{ (byte)128 } );具体有哪些属性,支持哪些命令可以参考MSDN中的Win32_Service:
    Win32_Service Class
      

  2.   

    UserControlService 虽然可以 InvokeMethod了,但是服务的OnCustomCommand(int command)方法却不响应... 
      

  3.   

    .NET Framework Class Library
    ServiceBase..::.OnCustomCommand Method Custom commands are raised by an ExecuteCommand statement in a ServiceController component. Use a switch statement or if..then condition to handle the custom commands you define on your service.MSDN好象只说了ServiceProcess.OnCustomCommand 能接受ServiceController.ExecuteCommand传来的命令...也看不到源代码,也不知道内部怎么实现的..还是用别的方法先好了