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. Web Development
  3. ASP.NET
  4. stopping service via WMI

stopping service via WMI

Scheduled Pinned Locked Moved ASP.NET
sysadminarchitecturehelptutorialquestion
4 Posts 2 Posters 2 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.
  • T Offline
    T Offline
    thespiff
    wrote on last edited by
    #1

    OK, I'm working on a web application that will allow you to start/stop a service running on a remote server via WMI. Here's the method that does it:

    public class GEServices
    { 
        public void Start(string ServiceName)
        {
            Object name;
            foreach (ManagementObject localService in allServices)
            {
                name = localService.GetPropertyValue("Name");
                if (name.ToString() == ServiceName)
                {
                    localService.InvokeMethod("StartService", null, null);
                    break;
                }
            }
        }
    }
    

    Now this method works perfectly fine when I call it from a simple test program. Here's an example of that code: GEServices BoxSvcs = new GEServices("\\\\my-pc"); BoxSvcs.Start("Alerter"); This cause no problems, so I think this code is solid. However, when I run the exact same code from the web application that I'm using this class in, the Alerter won't start and no errors show up. The only thing that I can think of is that the web app running on localhost doesn't have the same level of permissions as a local console app run by me. When I try to pass my credentials in when making the connection, I get an error saying I can't use credentials on connections to localhost. Any ideas out there?

    M T 2 Replies Last reply
    0
    • T thespiff

      OK, I'm working on a web application that will allow you to start/stop a service running on a remote server via WMI. Here's the method that does it:

      public class GEServices
      { 
          public void Start(string ServiceName)
          {
              Object name;
              foreach (ManagementObject localService in allServices)
              {
                  name = localService.GetPropertyValue("Name");
                  if (name.ToString() == ServiceName)
                  {
                      localService.InvokeMethod("StartService", null, null);
                      break;
                  }
              }
          }
      }
      

      Now this method works perfectly fine when I call it from a simple test program. Here's an example of that code: GEServices BoxSvcs = new GEServices("\\\\my-pc"); BoxSvcs.Start("Alerter"); This cause no problems, so I think this code is solid. However, when I run the exact same code from the web application that I'm using this class in, the Alerter won't start and no errors show up. The only thing that I can think of is that the web app running on localhost doesn't have the same level of permissions as a local console app run by me. When I try to pass my credentials in when making the connection, I get an error saying I can't use credentials on connections to localhost. Any ideas out there?

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi there, Take a look at this document and see the 'Using System.Management and WMI' section, that will give you a hint. Process and request identity in ASP.NET[^] However, I think using WMI in an ASP.NET application is just fit for the intranet, if you are going to put it on the internet, it's not a good idea.

      T 1 Reply Last reply
      0
      • M minhpc_bk

        Hi there, Take a look at this document and see the 'Using System.Management and WMI' section, that will give you a hint. Process and request identity in ASP.NET[^] However, I think using WMI in an ASP.NET application is just fit for the intranet, if you are going to put it on the internet, it's not a good idea.

        T Offline
        T Offline
        thespiff
        wrote on last edited by
        #3

        Yes, absolutely, this is an internal use only type deal. Thanks for the article, it sounds like my issue...but I've been running XP SP1 on this particular system since the day I brought it up from a clean format, and if I'm reading that article correctly it says I shouldn't have a problem. Also, I did try the workaround in that document, to no effect.

        1 Reply Last reply
        0
        • T thespiff

          OK, I'm working on a web application that will allow you to start/stop a service running on a remote server via WMI. Here's the method that does it:

          public class GEServices
          { 
              public void Start(string ServiceName)
              {
                  Object name;
                  foreach (ManagementObject localService in allServices)
                  {
                      name = localService.GetPropertyValue("Name");
                      if (name.ToString() == ServiceName)
                      {
                          localService.InvokeMethod("StartService", null, null);
                          break;
                      }
                  }
              }
          }
          

          Now this method works perfectly fine when I call it from a simple test program. Here's an example of that code: GEServices BoxSvcs = new GEServices("\\\\my-pc"); BoxSvcs.Start("Alerter"); This cause no problems, so I think this code is solid. However, when I run the exact same code from the web application that I'm using this class in, the Alerter won't start and no errors show up. The only thing that I can think of is that the web app running on localhost doesn't have the same level of permissions as a local console app run by me. When I try to pass my credentials in when making the connection, I get an error saying I can't use credentials on connections to localhost. Any ideas out there?

          T Offline
          T Offline
          thespiff
          wrote on last edited by
          #4

          I got it. This Microsoft article walks you through making your web app impersonate any user account you wish: http://support.microsoft.com/default.aspx?scid=kb%3BEN-US%3BQ306158[^] As long as the account your app impersonates has local admin rights on the server you are accessing you have full WMI power from your app. Very cool.

          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