Jump to content
Sign in to follow this  
kpu

Windows Service Status

Recommended Posts

Does anyone know how to find out if a service is running or stopped or how to stop it. I know you can use the "net stop" command, but thought there might be a better way.

I'm trying to stop and start the "System Restore Service". and verify that it has stopped.

Any info would be greatly appreciated!

Share this post


Link to post
Share on other sites

you may be able to check the return code...

$a = RunWait("net stop srservice","",@SW_HIDE)

MsgBox(4096,"",$a)

but I am not sure you can turn on and off the srservice in this way... you may need to research...

Lar.

<{POST_SNAPBACK}>

If you have no problems using a beta version of AutoIt, you can do things like this in the beta version 3.1.1.20:

; AutoITCOM 3.1.1
;
; Test file
;
; Stops and starts the 'Windows Update' service
;
; http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/reference/objects/ishelldispatch2/ishelldispatch2.asp

; Open Windows Shell object
$oShell=ObjCreate("shell.application")


if $oShell.IsServiceRunning("wuauserv") then  

   $oShell.ServiceStop("wuauserv",false)

   Msgbox(0,"Service Stopped","Service: automatic update services is now stopped")
   
   $oShell.ServiceStart("wuauserv",false)

   Msgbox(0,"Service Started","Service: automatic update services is started again")

endif

Regards,

-Sven

Share this post


Link to post
Share on other sites

Cool, I need to do this for a script I'm writing however, this only covers part of my task. Any ideas on how to;

Get the startup type of a service

Get a list of services

I've done some googling, but not had much luck :-(

Share this post


Link to post
Share on other sites

Cool, I need to do this for a script I'm writing however, this only covers part of my task. Any ideas on how to;

Get the startup type of a service

Get a list of services

I've done some googling, but not had much luck :-(

<{POST_SNAPBACK}>

You didn't commend on MHz's suggestion....

DESCRIPTION:
    SC is a command line program used for communicating with the 
    NT Service Controller and services.
USAGE:
    sc <server> [command] [service name] <option1> <option2>...

    The option <server> has the form "\\ServerName"
    Further help on commands can be obtained by typing: "sc [command]"
    Commands:
      query-----------Queries the status for a service, or 
                      enumerates the status for types of services.
      queryex---------Queries the extended status for a service, or 
                      enumerates the status for types of services.
      start-----------Starts a service.
      pause-----------Sends a PAUSE control request to a service.
      interrogate-----Sends an INTERROGATE control request to a service.
      continue--------Sends a CONTINUE control request to a service.
      stop------------Sends a STOP request to a service.
      config----------Changes the configuration of a service (persistant).
      description-----Changes the description of a service.
      failure---------Changes the actions taken by a service upon failure.
      qc--------------Queries the configuration information for a service.
      qdescription----Queries the description for a service.
      qfailure--------Queries the actions taken by a service upon failure.
      delete----------Deletes a service (from the registry).
      create----------Creates a service. (adds it to the registry).
      control---------Sends a control to a service.
      sdshow----------Displays a service's security descriptor.
      sdset-----------Sets a service's security descriptor.
      GetDisplayName--Gets the DisplayName for a service.
      GetKeyName------Gets the ServiceKeyName for a service.
      EnumDepend------Enumerates Service Dependencies.

    The following commands don't require a service name:
    sc <server> <command> <option> 
      boot------------(ok | bad) Indicates whether the last boot should
                      be saved as the last-known-good boot configuration
      Lock------------Locks the Service Database
      QueryLock-------Queries the LockStatus for the SCManager Database
EXAMPLE:
    sc start MyService

Would you like to see help for the QUERY and QUERYEX commands? [ y | n ]:

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

I don't have much time to read this now, but yeah, it looks quite good. Sorry I missed it, but I was thinking more along the lines of COM stuff. I know there was some great UDFs posted when we had DLL support added, and now with COM it's reduced some of it to just a few lines.

Still, sometimes we have to rely on good ol' fashioned external proggies. But if they do the job, hey why not.

Thanks in advance, will post my thoughts when I've had more of a play.

Share this post


Link to post
Share on other sites

What I ended up doing is using the "sc \\PC start srservce" then sleeping for a second or two. I would then run "sc \\PC queryex srservce > startus.txt" for a little error control, reads the file for the message and made some "if" statements.

It's not pretty, but it gets the job done. Thanks MHz for the command. I found you can do quite a bit with it. For instance Telnet is disabled on our images. Using the sc command I can change it from manual to demand, start it. After I'm done, I can then stop it and disable it.

Thanks for eveyone assistance on this! :(

I don't have much time to read this now, but yeah, it looks quite good. Sorry I missed it, but I was thinking more along the lines of COM stuff. I know there was some great UDFs posted when we had DLL support added, and now with COM it's reduced some of it to just a few lines.

Still, sometimes we have to rely on good ol' fashioned external proggies. But if they do the job, hey why not.

Thanks in advance, will post my thoughts when I've had more of a play.

<{POST_SNAPBACK}>

Share this post


Link to post
Share on other sites

Thanks MHz for the command. I found you can do quite a bit with it.

Thanks kpu for the friendly gesture. :(

SC.exe is specialized for services, so it is useful.

Com usage with WMI etc. as Sven's example has displayed, should be the ultimate for administrators, when it hits it's prime. Com will launch Autoit into a new era. My thanks also to Sven, and his great examples. :(

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...