Jump to content

checking for a service?


 Share

Recommended Posts

I was looking to see if Autoit could check for a service to see if its running but I cant lcoate an AutoIt command. In the past, I had psservice export the service list to a text file, then query the text file for the service name.

any assistance would be appreciated.

Thank You

Lavelle

Link to comment
Share on other sites

I was looking to see if Autoit could check for a service to see if its running but I cant lcoate an AutoIt command. In the past, I had psservice export the service list to a text file, then query the text file for the service name.

any assistance would be appreciated.

Thank You

Lavelle

You could lookup the DOS command sc


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

Here's what I've done to check remote systems and start it. Not pretty, but it does the job.

Here's a list of services:

browser|TrkWks|ERSvc|helpsvc|CiSvc|dmserver|Netlogon|mnmsrvc|SysmonLog|WmdmPmSN|

RSVP|RDSessMgr|RemoteRegistry|seclogon|SamSs|lanmanserver|SCardSvr|SSDPRSRV|

srservice|LmHosts|TlntSvr|UPS|upnphost|w32Time|WZCSVC

This will:

1. Connect to remote computer.

2. Change the service to Demand

3. Start the service and sleep for a couple seconds

4. Query the service. If the service is pending, it will loop until it's started.

5. Close Connection

6. Exit

Here ya go.

$service = "TlntSvr";telnet service. Case Sensitive !!
$pc = "computer"
$pw = "password"

;Connect to remote IPC Share.
RunWait(@ComSpec & " /c " & "net use \\" & $pc & "\IPC$ /U:Administrator " & $pw & " > temp.txt", "", @SW_HIDE)
;Set service to Demand (boot|system|auto|demand|disabled)
RunWait(@ComSpec & " /c " & "sc \\" & $pc & " config " & $service & " start= demand", "", @SW_HIDE)
;start service
RunWait(@ComSpec & " /c " & "sc \\" & $pc & " start " & $service, "", @SW_HIDE)
Sleep(2000);Wait for service to start.
;Query service for status
RunWait(@ComSpec & " /c " & "sc \\" & $pc & " query " & $service & " > temp.txt", "", @SW_HIDE)
$file = FileOpen("temp.txt", 0)
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
While 1
    $line = FileReadLine($file, 4)
    If $line = "        STATE             : 2  START_PENDING " Then
        RunWait(@ComSpec & " /c " & "sc \\" & $pc & " query " & $service & " > temp.txt", "", @SW_HIDE)
        Sleep(1000)
   ElseIf $line = "     STATE             : 4  RUNNING " Then
        MsgBox(32, "Success", "Service Running")
        Exit
    Else
        MsgBox(16,"Warning!","Something Didn't work correctly. Opening Temp File",3)
        Run("temp.txt")
        exit
    EndIf
WEnd
FileClose($file)
;Close Network session
RunWait(@ComSpec & " /c " & "net use" & " \\" & $pc & "\IPC$ /delete", "", @SW_HIDE
Edited by kpu
Link to comment
Share on other sites

  • 11 months later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...