Jump to content

Start process from service window


 Share

Recommended Posts

Put quotes around the service name.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

You can use the Windows Services UDF to work with services, instead of the command line.  A few examples are below.  

Using the known service name and computer.

#RequireAdmin
#include <Services.au3>

Global $sServiceName = "AppMgmt"
Global $sComputer = "shital-PC"

;Check the status of the service, if it is stopped, start it.  
Global $aService = 0
Do
    $aService = _Service_QueryStatus($sServiceName, $sComputer)
    If @error Then Exit 1
    
    If $aService[1] = $SERVICE_STOPPED Then 
        If Not _Service_Start($sServiceName, $sComputer) Then Exit 2
    EndIf
    
    Sleep(500) ;Wait 500 ms.
Until $aService[1] = $SERVICE_RUNNING

Using known service display name and computer.  

#RequireAdmin
#include <Array.au3>
#include <Services.au3>

Global $sComputer = "shital-PC"

;Get a list of all services.
Global $aServices = _Service_Enum($SERVICE_WIN32, $SERVICE_STATE_ALL, Default, $sComputer)
If @error Then Exit 1

;Search for the service display name.
Global $sSearch = "XYX Processing service"

Global $aFound = _ArrayFindAll($aServices, $sSearch, 1, 0, 0, 1, 1) ;Starting with row 1, partial search, 2D array column 1.
If @error Then Exit 1 + @error

;If more than one service is found, exit.
If UBound($aFound) > 1 Then Exit 8

;Get service name from found service display name.
Global $sServiceName = $aServices[$aFound[0]][0]

;Check the status of the service, if it is stopped, start it.  
Global $aService = 0
Do
    $aService = _Service_QueryStatus($sServiceName, $sComputer)
    If @error Then Exit 9
    
    If $aService[1] = $SERVICE_STOPPED Then 
        If Not _Service_Start($sServiceName, $sComputer) Then Exit 10
    EndIf
    
    Sleep(500) ;Wait 500 ms.
Until $aService[1] = $SERVICE_RUNNING

 

Adam

 

Edited by AdamUL
Link to comment
Share on other sites

  • 3 weeks later...

Actually ,

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile_type=a3x
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Services.au3>

Global $sServiceName = "Intell Processing Service"
Global $sComputer = "el66"

;Check the status of the service, if it is stopped, start it.
Global $aService = 0
Do
    $aService = _Service_QueryStatus($sServiceName, $sComputer)
    If @error Then Exit 1

    If $aService[1] = $SERVICE_STOPPED Then
        If Not _Service_Start($sServiceName, $sComputer) Then Exit 2
    EndIf

    Sleep(500) ;Wait 500 ms.
Until $aService[1] = $SERVICE_RUNNING

These code not working due to service name space . That same issue it wasn't solved  yet and  other  code run exe but  my services not start with exe it work with sc or net start .My point is i want check service running or not after some interval and if its not work again  service should start on remote pc .

Link to comment
Share on other sites

Try this for the spaces in the name issue.

Global $sServiceName = '"Intell Processing Service"'

I added quotes around the service name.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Are you sure that is the service name, and not the service display name?  The UDF needs the service name to work.  This script searches for the service name based on its display name.  I posted this above, but I'll include it here with the update information you gave.  You need admin rights on the remote PC for it to work.  

#RequireAdmin
#include <Array.au3>
#include <Services.au3>

Global $sComputer = "el66"

;Get a list of all services.
Global $aServices = _Service_Enum($SERVICE_WIN32, $SERVICE_STATE_ALL, Default, $sComputer)
If @error Then Exit 1

;Search for the service display name using partial name.
Global $sSearch = "Intell Processing"

Global $aFound = _ArrayFindAll($aServices, $sSearch, 1, 0, 0, 1, 1) ;Starting with row 1, partial search, 2D array column 1.
If @error Then Exit 1 + @error

;If more than one service is found, exit.
If UBound($aFound) > 1 Then Exit 8

;Get service name from found service display name.
Global $sServiceName = $aServices[$aFound[0]][0]

;Check the status of the service, if it is stopped, start it.  
Global $aService = 0
Do
    $aService = _Service_QueryStatus($sServiceName, $sComputer)
    If @error Then Exit 9
    
    If $aService[1] = $SERVICE_STOPPED Then 
        If Not _Service_Start($sServiceName, $sComputer) Then Exit 10
    EndIf
    
    Sleep(100) ;Wait 100 ms.
Until $aService[1] = $SERVICE_RUNNING

Or you can check the service name with the service.msc and it properties.  Example below.  The service name is highlighted.  

783843399_ServiceProperties.png.01bf5149a41f86d50444fbf781fb731e.png

 

Adam

Link to comment
Share on other sites

something like

$result = RunWait(@ComSpec & ' /c net start server', $varPath & '\YourServiceExename.exe', @SW_HIDE)

or use the built in windows SC command, it's super easy. SC Start "Your Service Name here"

https://commandwindows.com/sc.htm

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

Its not feasible to change service name .if possible plz give me another way ..i want run that script on scheduler  and that task pending from long .


 
Global $sServiceName = '"Intell Processing Service"'

these also not working not

Edited by shital
Link to comment
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
 Share

  • Recently Browsing   0 members

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