Jump to content

Control Start/Stop Services


Recommended Posts

Hi,

Here bellow my script to add/copy French Language to Diskeeper.

In fact, Diskeeper Service it NOT completely stopped when the "DK781_FR.exe" (see script) start copying...wihtout success. Moreover, Diskeeper Service restart.

;Stop Diskeeper Service  
RunWait("net stop Diskeeper", "C:\windows\system32")

;Copy Diskeeper FR Language
$Lang = RegRead("HKEY_CURRENT_USER\Control Panel\International", "sLanguage")
If $Lang = "FRA" Then
    RunWait("DK781_FR.exe")
EndIf

;Start Diskeeper Service  
RunWait("net start Diskeeper", "C:\windows\system32")

Any Help on how to control the stop/start service (wait until the service is completely stop/start before the next command) be appreciated.

Regards

coucou

Link to comment
Share on other sites

Hi,

there is a services udf.

Try using a loop until status is stopped.

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Hi,

Here bellow my script to add/copy French Language to Diskeeper.

In fact, Diskeeper Service it NOT completely stopped when the "DK781_FR.exe" (see script) start copying...wihtout success. Moreover, Diskeeper Service restart.

;Stop Diskeeper Service  
RunWait("net stop Diskeeper", "C:\windows\system32")

;Copy Diskeeper FR Language
$Lang = RegRead("HKEY_CURRENT_USER\Control Panel\International", "sLanguage")
If $Lang = "FRA" Then
    RunWait("DK781_FR.exe")
EndIf

;Start Diskeeper Service  
RunWait("net start Diskeeper", "C:\windows\system32")

Any Help on how to control the stop/start service (wait until the service is completely stop/start before the next command) be appreciated.

Regards

coucou

You can get much more info on services from WMI, i.e. ".state" which can be "stopped" or "stopping" and "running" or "starting":
Global Const $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20
Global $wbemFlags = BitOR($wbemFlagReturnImmediately, $wbemFlagForwardOnly)

$objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
$sQuery = "SELECT * FROM Win32_Service"
$colItems = $objWMIService.ExecQuery($sQuery, "WQL", $wbemFlags)

For $objItem In $colItems
    ConsoleWrite("Name: " & $objItem.Name & @LF)
    ConsoleWrite("Started: " & $objItem.Started & @LF)
    ConsoleWrite("State: " & $objItem.State & @LF & @LF)
Next

To only get results for one service change this:

$sQuery = "SELECT * FROM Win32_Service WHERE Name = 'ccEvtMgr'"

Reference: MSDN: Win32_Service:

State

Data type: string

Access type: Read-only

Current state of the base service.

The values are: "Stopped", "Start Pending", "Stop Pending", "Running", "Continue Pending", "Pause Pending",

"Paused", or "Unknown"

muttley Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

TNX PsaltyDS for yr help.

As i'm not script experimented, I confess that i don't know how to insert that control in my script muttley

;Stop Diskeeper Service  
RunWait("net stop Diskeeper", "C:\windows\system32")

;Here to insert the service control
;If Diskeeper Service is stop Then
  ;Copy Diskeeper FR Language
   $Lang = RegRead("HKEY_CURRENT_USER\Control Panel\International", "sLanguage")
     If $Lang = "FRA" Then
        RunWait("DK781_FR.exe")
     EndIf
;EndIf

;Start Diskeeper Service  
RunWait("net start Diskeeper", "C:\windows\system32")
;Here to insert the service control
;If Diskeeper Service is start Then
    Exit
;EndIf

I'll appreciate a ready made script

Regards

coucou

Link to comment
Share on other sites

TNX PsaltyDS for yr help.

As i'm not script experimented, I confess that i don't know how to insert that control in my script :(

;Stop Diskeeper Service  
RunWait("net stop Diskeeper", "C:\windows\system32")

;Here to insert the service control
;If Diskeeper Service is stop Then
;Copy Diskeeper FR Language
   $Lang = RegRead("HKEY_CURRENT_USER\Control Panel\International", "sLanguage")
     If $Lang = "FRA" Then
        RunWait("DK781_FR.exe")
     EndIf
;EndIf

;Start Diskeeper Service  
RunWait("net start Diskeeper", "C:\windows\system32")
;Here to insert the service control
;If Diskeeper Service is start Then
    Exit
;EndIf

I'll appreciate a ready made script

Regards

coucou

This method should work for you without using anything you are not familiar with already:
; Stop Diskeeper Service
RunWait("net stop Diskeeper", "C:\windows\system32")

; See if it's still running
$sTempFile = @ScriptDir & "\ServiceList.txt"
RunWait('net start > "' & $sTempFile & '"', "C:\windows\system32")
$sServiceList = FileRead($sTempFile)
If StringInStr($sServiceList, "Diskeeper") Then
    MsgBox(16, "Error", "Failed to stop Diskeeper service")
Else
; Copy Diskeeper FR Language
    $Lang = RegRead("HKEY_CURRENT_USER\Control Panel\International", "sLanguage")
    If $Lang = "FRA" Then RunWait("DK781_FR.exe")
    
; Start Diskeeper Service
    RunWait("net start Diskeeper", "C:\windows\system32")
    RunWait('net start > "' & $sTempFile & '"', "C:\windows\system32")
    $sServiceList = FileRead($sTempFile)
    If StringInStr($sServiceList, "Diskeeper") Then
        MsgBox(64, "Success", "Successfully restarted Diskeeper service")
    Else
        MsgBox(16, "Error", "Failed to restart Diskeeper service")
    EndIf
EndIf

...there is a services udf.

@Xenobiologist: Where? The efforts I have found have been pretty fragmentary. Is there a good Services.au3 UDF out there? Could you post a link to your favorite.

muttley

Edit: Found one by GEOSoft: Services UDF, don't know why it didn't come up in my earlier search.

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...