Jump to content

Recommended Posts

Posted

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

Posted (edited)
$StartService = _RunDos(' net start "CryptSvc"  ' )

my service name  " XYX   Processing service"

its nt working above command what mistake in syntax

Edited by shital
Posted (edited)

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
  • 3 weeks later...
Posted (edited)

I guess im not getting your code.for running first code it showing 

#include <Services.au3> undefine .

if possible can u plz  describe Services.au3 not library  then which file is Services.au3

Edited by shital
Posted

Thanks found code 

One more things   it open window poup and ask for allow autoit program  tp run .is that anyway to suppress it ?

Posted

This is due to the #RequireAdmin directive causing a UAC prompt.  How do you plan to deploy the script?  This determines how, and if you need to suppress the prompt.  

 

Adam

 

Posted

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 .

Posted

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

Posted

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

Posted

 our product service name have space . Can anyone help me regarding space service name i have tried all way for space still service nt get start.

Posted (edited)

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

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
  • Recently Browsing   0 members

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