Jump to content
shital

Start process from service window

Recommended Posts

Script should check after some time process status if it is stop then start it on remote pc . process should start from service window as  by run command  that particular process not starting . ShellExecute("C:\Windows\System32\en-US\services.msc") use for open service but how to select particular service i didnt get that 

Share this post


Link to post
Share on other sites

Have a look at SC via command prompt, you can query, start, stop or configure services directly via CMD.  Alternatively search the forums for a services udf, I know there have been a few made by various forum members.

Share this post


Link to post
Share on other sites

Software nt run from  command  prompt.it's process nt start by hitting exe  as installation of it's different . options only to go to service n start tht process  ..I  didn't get how to click on tht particular process in service windows bec  by recorder it nt show process entry .

 

 

 

 

Share this post


Link to post
Share on other sites

Actually  , 

 
net start "Processing Service" these command i want use in autoit script.

$servicename="give me a name please"

Run (@comspec & ' /c sc query '&$servicename, '', @sw_hide)

 these not working for me .might be im doing something wrong .

Share this post


Link to post
Share on other sites

$servicename=" Processing Service"

Run (@comspec & ' /c sc query '&$servicename, '', @sw_hide)

Share this post


Link to post
Share on other sites

try this

you are going to need to be administrator though or it gets Access Denied

here is your starter script

#RequireAdmin
 

#RequireAdmin

run("cmd.exe /c sc query "&$servicename, "", @SW_HIDE)

run("cmd.exe /c sc stop "&$servicename, "", @SW_HIDE)

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites

Have a look at the following thread, which shows you how to get the status of  a service, I prefer the WMI approach, just use it in an if statement and use SC to start/stop the service.

 

Share this post


Link to post
Share on other sites
#include <Constants.au3>
#include <MsgBoxConstants.au3>
global $servicename="AppMgmt"
global $user="shital"
global $pw=""


global $sCommand = "run(cmd.exe /c sc query &$servicename, "", @SW_HIDE)"
global $iPID = Runas($user, @LogonDomain, $pw, "",@ComSpec & " /c " & $sCommand,"",@SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($iPID)
global $sOutput = StdoutRead($iPID)
ConsoleWrite($sOutput)

its nt working any syntax error 

Edited by shital

Share this post


Link to post
Share on other sites

As I mentioned follow the link I posted above, it includes an SC Query example + WMI  example, all you have to do is change the service name.

Share this post


Link to post
Share on other sites

I have modify above code. as code should work for remote pc . When i remove 

MsgBox(0, $service, _RetrieveServiceState("shital-PC", $service))

 process not start .I didnt get that .Also I dont want manually click on messagebox as it will inside webDriver script .Any help regarding it 





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

$service = "AppMgmt"

$s_Machine="shital-PC"
$s_ServiceName="AppMgmt"
MsgBox(0, $service, _RetrieveServiceState("shital-PC", $service))

Func _RetrieveServiceState($s_Machine, $s_ServiceName)
    Local Const $wbemFlagReturnImmediately = 0x10
    Local Const $wbemFlagForwardOnly = 0x20
    Local $colItems = "", $objItem

        Local $usr = "", $pass = ""; set this only if different from current user

      Local $objWMILocator = ObjCreate("WbemScripting.SWbemLocator")
    Local $objWMIService = $objWMILocator.ConnectServer($s_Machine, "\root\cimv2", $usr, $pass, "", "", "&H80")
    If @error Then
        MsgBox(16, "_RetrieveServiceState", "ObjGet Error: winmgmts")
        Return
    EndIf

    $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Service WHERE Name = '" & $s_ServiceName & "'", "WQL", _
            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    If @error Then
        MsgBox(16, "_RetrieveServiceState", "ExecQuery Error: SELECT * FROM Win32_Service")
        Return
    EndIf
    If IsObj($colItems) Then
                    $StartService = _RunDos("net start AppMgmt")

EndIf
EndFunc   ;==>_RetrieveServiceState

 

Edited by shital

Share this post


Link to post
Share on other sites

How to click on ok button of MsgBox(0, $service, _RetrieveServiceState("shital-PC", $service))

when ok button click then only service get start . i tried winactive,controlclick,mouseclick,send ({enter}) nothing work plz help

Share this post


Link to post
Share on other sites

Thanks,it working . 

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

 global $service = "AppMgmt"

 global $s_Machine="shital-PC"
 global $s_ServiceName="AppMgmt"

call(_RetrieveServiceState("shital-PC", $s_ServiceName))


Func _RetrieveServiceState($s_Machine, $s_ServiceName)

    Local $colItems = "", $objItem
Local Const $wbemFlagReturnImmediately = 0x10
    Local Const $wbemFlagForwardOnly = 0x20
    If Not Ping("shital-PC") Then Return SetError(1, 0, "")
    Local $usr = "", $pass = ""; set this only if different from current user


      Local $objWMILocator = ObjCreate("WbemScripting.SWbemLocator")
    Local $objWMIService = $objWMILocator.ConnectServer($s_Machine, "\root\cimv2", $usr, $pass, "", "", "&H80")


    $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Service WHERE Name = '" & $s_ServiceName & "'", "WQL", _
            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems) Then
                    $StartService = _RunDos("net start AppMgmt")

EndIf
EndFunc   ;==>_RetrieveServiceState

 

Edited by shital

Share this post


Link to post
Share on other sites

I need one more help my service name is processing service .it's has space so it's nt running 

Share this post


Link to post
Share on other sites

please, can you use the code tags when you post code? you click on the thing that looks like this: <> and put your code in there. that way it's all nicely formatted and easier to read

 

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

 global $service = "AppMgmt"

 global $s_Machine="shital-PC"
 global $s_ServiceName="AppMgmt"

call(_RetrieveServiceState("shital-PC", $s_ServiceName))


Func _RetrieveServiceState($s_Machine, $s_ServiceName)

    Local $colItems = "", $objItem
Local Const $wbemFlagReturnImmediately = 0x10
    Local Const $wbemFlagForwardOnly = 0x20
    If Not Ping("shital-PC") Then Return SetError(1, 0, "")
    Local $usr = "", $pass = ""; set this only if different from current user


      Local $objWMILocator = ObjCreate("WbemScripting.SWbemLocator")
    Local $objWMIService = $objWMILocator.ConnectServer($s_Machine, "\root\cimv2", $usr, $pass, "", "", "&H80")


    $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Service WHERE Name = '" & $s_ServiceName & "'", "WQL", _
            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems) Then
                    $StartService = _RunDos("net start AppMgmt")

EndIf
EndFunc   ;==>_RetrieveServiceState

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

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

×
×
  • Create New...