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. Visual Basic
  4. Windows Services

Windows Services

Scheduled Pinned Locked Moved Visual Basic
question
4 Posts 2 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.
  • S Offline
    S Offline
    Shenthil
    wrote on last edited by
    #1

    Hi, How can I start / stop a windows service from my vb application. can I get a sample Shenthil

    D 1 Reply Last reply
    0
    • S Shenthil

      Hi, How can I start / stop a windows service from my vb application. can I get a sample Shenthil

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      VB6 (w/o WMI): You'll have to call into the Windows API's to get in touch with the Service Control Manager to start and stop Services. VB6 (with WMI): You can use WMI to get a list of Win32_BaseService objects. You can then use simple method calls to start and stop the service(s) you want. VB.NET: Very easy. See the documentation on the ServiceController class. RageInTheMachine9532

      S 1 Reply Last reply
      0
      • D Dave Kreskowiak

        VB6 (w/o WMI): You'll have to call into the Windows API's to get in touch with the Service Control Manager to start and stop Services. VB6 (with WMI): You can use WMI to get a list of Win32_BaseService objects. You can then use simple method calls to start and stop the service(s) you want. VB.NET: Very easy. See the documentation on the ServiceController class. RageInTheMachine9532

        S Offline
        S Offline
        Shenthil
        wrote on last edited by
        #3

        Thanks. can u give me more detail about using with WMI in vb6.0. Now I am working without WMI. shenthil

        D 1 Reply Last reply
        0
        • S Shenthil

          Thanks. can u give me more detail about using with WMI in vb6.0. Now I am working without WMI. shenthil

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          VB6 with WMI: This will stop a service and it's dependants:

          ' The "." mean the local computer.
          strComputer = "."
           
          ' We're going to stop the NetDDE service.
          ' First, get the list of dependent services and stop them one by one.
          Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
          Set colServiceList = objWMIService.ExecQuery("Associators of {Win32_Service.Name='NetDDE'} Where AssocClass=Win32_DependentService Role=Antecedent")
          For each objService in colServiceList
          objService.StopService()
          Next
           
          ' We just told the dependent services to stop. Now we'll wait about 20 seconds
          ' before we tell the NetDDE service to stop.
          Wscript.Sleep 20000
           
          ' ...and, finally, stop the NetDDE service.
          Set colServiceList = objWMIService.ExecQuery("Select * from Win32_Service where Name='NetDDE'")
          For each objService in colServiceList
          errReturn = objService.StopService()
          Next

          RageInTheMachine9532

          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