#include <GUIConstants.au3>
GUICreate("Service")
GUICtrlCreateLabel("Enter service name:", 10, 10)
$s = GUICtrlRead(GUICtrlCreateInput("", 10, 30))
$ok_but = GUICtrlCreateButton ("OK",120,30)
GUISetState ()
Do
$msg = GUIGetMsg()
Until $msg = $GUI_EVENT_PRIMARYDOWN
$pid=Run('sc query $s','','',0x2)
$read=''
While 1
$read &= StdoutRead($pid)
If @error Then ExitLoop
Sleep(1)
WEnd
$str=StringRegExp($read,'STATE.*?:\s\d.\s{1,}(\S+)',1)
; MsgBox(0,'',$str[0])
GUICtrlCreateLabel("Service is " & $str, 10, 50)
$u = GUICtrlCreateInput("", 10, 30)
$but_start = GUICtrlCreateButton ("Start",10,110)
;GUICtrlSetState(-1,$GUI_FOCUS) ; the focus is on this button
$but_stop = GUICtrlCreateButton ("Stop",40,110)
GUISetState ()
; Run the GUI until the dialog is closed
Do
$msg = GUIGetMsg()
if $msg = $but_start then
RunWait(@ComSpec &' /c net start ' & $s,'', @SW_HIDE)
Else
RunWait(@ComSpec &' /c net stop ' & $s,'', @SW_HIDE)
endif
Until $msg = $GUI_EVENT_CLOSE
; НАЧАЛО
$NAME=InputBox("Проверка состояния службы","Введите название службы","wuauserv")
$KEY="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\"&$NAME
$VALUE=RegRead($KEY,"Start")
Switch $VALUE
Case 2
$STATE="Автоматически"
Case 3
$STATE="Вручную"
Case 4
$STATE="Остановлена"
Case Else
$STATE="Не определено"
EndSwitch
MsgBox(0,"Состояние",$STATE)
; КОНЕЦ
$s='dhcp'
$pid=Run('sc query '&$s,'',@SW_HIDE,0x2)
$read=''
While 1
$read &= StdoutRead($pid)
If @error Then ExitLoop
Sleep(1)
WEnd
;~ MsgBox(0,'',$read)
If StringInStr($read,'STATE')=0 Then MsgBox(0,'','проблемы в коде выше')
$str=StringRegExp($read,'STATE.*?:\s\d.\s{1,}(\S+)',1)
MsgBox(0,'',$str[0])
Run('sc')
_Service_GetState()
#Include <Services.au3>
ConsoleWrite(_Service_GetState("Dhcp"))
Running
#Include <Services.au3>
#Include <GUIConstantsEx.au3>
$Form1 = GUICreate("Service", 211, 288, 585, 140)
$Label1 = GUICtrlCreateLabel("Enter service name:", 16, 8, 98, 17)
$Input1 = GUICtrlCreateInput("", 32, 24, 161, 21)
$Button1 = GUICtrlCreateButton("OK", 120, 48, 75, 25)
$Label2 = GUICtrlCreateLabel("", 16, 104, 180, 20)
$Button2 = GUICtrlCreateButton("Start Service", 24, 152, 75, 25)
GUICtrlSetState($Button2, $GUI_DISABLE)
$Button3 = GUICtrlCreateButton("Stop Service", 104, 152, 75, 25)
GUICtrlSetState($Button3, $GUI_DISABLE)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
_SRV_TEST()
Case $Button2
_SRV_START()
Case $Button3
_SRV_STOP()
EndSwitch
WEnd
;~ Проверяем состояние службы
Func _SRV_TEST()
Local $SRV_TEST = _Service_GetState(GUICtrlRead($Input1))
GUICtrlSetState($Button2, $GUI_DISABLE)
GUICtrlSetState($Button3, $GUI_DISABLE)
If (GUICtrlRead($Input1) <> "") Then
If ($SRV_TEST == "Running") Then
GUICtrlSetData($Label2, "Service is "&$SRV_TEST)
GUICtrlSetState($Button3, $GUI_ENABLE)
ElseIf ($SRV_TEST == "Stopped") Then
GUICtrlSetData($Label2, "Service is "&$SRV_TEST)
GUICtrlSetState($Button2, $GUI_ENABLE)
Else
GUICtrlSetData($Label2, "ERROR: Service not found !!!")
EndIf
Else
GUICtrlSetData($Label2, "ERROR: enter service name !!!")
EndIf
EndFunc
;~ Запускаем службу
Func _SRV_START()
_Service_Start(GUICtrlRead($Input1))
GUICtrlSetState($Button2, $GUI_DISABLE)
GUICtrlSetState($Button3, $GUI_ENABLE)
GUICtrlSetData($Label2, "Service is "&_Service_GetState(GUICtrlRead($Input1)))
EndFunc
;~ Останавливаем службу
Func _SRV_STOP()
_Service_Stop(GUICtrlRead($Input1))
GUICtrlSetState($Button2, $GUI_ENABLE)
GUICtrlSetState($Button3, $GUI_DISABLE)
GUICtrlSetData($Label2, "Service is "&_Service_GetState(GUICtrlRead($Input1)))
EndFunc
Проблема не в массиве, а в вашей спешке
Увы, у меня нет Services.au3, у меня стандартная поставка 3.3.8.1. Где взять?
Func sc ($s='dhcp')
$pid=Run('sc query '&$s,'',@SW_HIDE,0x2)
$read=''
While 1
$read &= StdoutRead($pid)
If @error Then ExitLoop
Sleep(1)
WEnd
If StringInStr($read,'STATE')=0 Then MsgBox(0,'','проблемы в коде выше')
$str=StringRegExp($read,'STATE.*?:\s\d.\s{1,}(\S+)',1)
MsgBox(0,'',$str[0])
EndFunc
$Gui=GUICreate("123")
$Button_1 = GUICtrlCreateButton("тык", 10, 50, 120)
$combo=GUICtrlCreateCombo('w32time',1,1)
GUICtrlSetData ($combo,'netlogon|dhcp|cisvc')
GUISetState()
While 1
$msg = GUIGetMsg()
Switch $msg
Case -3
ExitLoop
Case $Button_1
$s=GUICtrlRead($combo)
sc($s)
EndSwitch
WEnd
$pid=Run('sc query dhcp','','',0x2)
$read=''
While 1
$read &= StdoutRead($pid)
If @error Then ExitLoop
Sleep(1)
WEnd
$str=StringRegExp($read,'STATE.*?:\s\d.\s{1,}(\S+)',1)
MsgBox(0,'',$str[0])
"D:\SSD\Users\-\Desktop\11111111.au3" (9) : ==> Subscript used on non-accessible variable.:
MsgBox(0,'',$str[0])
MsgBox(0,'',$str^ ERROR
$pid=Run('sc query dhcp','','',0x2)
$read=''
While 1
$read &= StdoutRead($pid)
If @error Then ExitLoop
Sleep(1)
WEnd
clipput($read)
MsgBox(0,'',$read)
;$str=StringRegExp($read,'STATE.*?:\s\d.\s{1,}(\S+)',1)
;MsgBox(0,'',$str[0])
"E:\D\A\MS\W\7\Twk\Pack\Old\1 (2).au3" (9) : ==> Subscript used on non-accessible variable.:
MsgBox(0,'',$str[0])
MsgBox(0,'',$str^ ERROR
"E:\D\A\MS\W\7\Twk\Pack\Old\1 (2).au3" (9) : ==> Subscript used on non-accessible variable.:
MsgBox(0,'',$str[0])
MsgBox(0,'',$str^ ERROR
Global $STANDARD_RIGHTS = 0x000F0000
Global $SCMAN_ALL_ACCESS = BitOR( $STANDARD_RIGHTS, 0x0000003F )
Global Const $SCMAN_CONNECT = 0x00000001, _
$SCMAN_CREATE_SERVICE = 0x00000002, _
$SCMAN_ENUMERATE_SERVICE = 0x00000004, _
$SCMAN_LOCK = 0x00000008, _
$SCMAN_QUERY_LOCK_STATUS = 0x00000010, _
$SCMAN_MODIFY_BOOT_CONFIG = 0x00000020
Global $SVC_ALL_ACCESS = BitOR( $STANDARD_RIGHTS, 0x000001FF )
Global Const $SVC_QUERY_CONFIG = 0x00000001, _
$SVC_CHANGE_CONFIG = 0x00000002, _
$SVC_QUERY_STATUS = 0x00000004, _
$SVC_ENUMERATE_DEPENDENTS = 0x00000008, _
$SVC_START = 0x00000010, _
$SVC_STOP = 0x00000020, _
$SVC_PAUSE_CONTINUE = 0x00000040, _
$SVC_INTERROGATE = 0x00000080, _
$SVC_USER_DEFINED_CONTROL = 0x00000100
Global Const $SVC_CONTROL_STOP = 0x00000001, _
$SVC_CONTROL_PAUSE = 0x00000002, _
$SVC_CONTROL_INTERROGATE = 0x00000004
Global Const $SVC_KERNEL_DRIVER = 0x00000001, _
$SVC_FILE_SYSTEM_DRIVER = 0x00000002, _
$SVC_ADAPTER = 0x00000004, _
$SVC_RECOGNIZER_DRIVER = 0x00000008, _
$SVC_WIN32_OWN_PROCESS = 0x00000010, _
$SVC_WIN32_SHARE_PROCESS = 0x00000020, _
$SVC_INTERACTIVE_PROCESS = 0x100
Global Enum $SVC_BOOT_START, _
$SVC_SYSTEM_START, _
$SVC_AUTO_START, _
$SVC_DEMAND_START, _
$SVC_DISABLED
Global Enum $SVC_ERROR_IGNORE, _
$SVC_ERROR_NORMAL, _
$SVC_ERROR_SEVERE, _
$SVC_ERROR_CRITICAL
;===============================================================================
; Description: Starts a service on a computer
;===============================================================================
Func _StartService($hService, $sComputerName = "")
Local $vRet = DllCall("advapi32.dll", "int", "StartService", "handle", $hService, "long", 0, "str", "")
If Not IsArray( $vRet ) Or Not $vRet[0] Then _
$vRet = _GetServiceError()
Return $vRet[0]
EndFunc
;===============================================================================
; Description: Stops a service on a computer
;===============================================================================
Func _StopService($hService, $sComputerName = "")
Local $vRet = DllCall("advapi32.dll", "int", "ControlService", "handle", $hService, "long", $SVC_CONTROL_STOP, "str", "")
If Not IsArray( $vRet ) Or Not $vRet[0] Then _
$vRet = _GetServiceError()
Return $vRet[0]
EndFunc
;===============================================================================
; Description: Checks if a service is running on a computer
;===============================================================================
Func _ServiceRunning($hService, $sComputerName = "")
Local $vRet = DllCall("advapi32.dll", "int", "ControlService", "handle", $hService, "long", $SVC_CONTROL_INTERROGATE, "str", "")
If Not IsArray( $vRet ) Then _
$vRet = Null
Return $vRet[0]
EndFunc
;===============================================================================
; Description: Deletes a service on a computer
;===============================================================================
Func _DeleteService($hService, $sComputerName = "")
Local $vRet = DllCall("advapi32.dll", "int", "DeleteService", "handle", $hService)
If Not IsArray( $vRet ) Or Not $vRet[0] Then _
$vRet = _GetServiceError()
Return $vRet[0]
EndFunc
;===============================================================================
; Description: Creates a service on a computer
;===============================================================================
Func _CreateService($hSCMan, $sServiceName, $sDisplayName, $iDesiredAccess, $iType, $iStartType, $iErrorControl, $sPath)
Local $vRet = DllCall("advapi32.dll", "handle", "CreateService", "handle", $hSCMan, "str", $sServiceName, "str", $sDisplayName, "dword", $iDesiredAccess, _
"dword", $iType, "dword", $iStartType, "dword", $iErrorControl, "str", $sPath, "ptr", 0, "ptr", 0, "ptr", 0, "ptr", 0, "ptr", 0 )
If Not IsArray( $vRet ) Or Not $vRet[0] Then _
$vRet = _GetServiceError()
Return $vRet[0]
EndFunc
Func _OpenSCManager($sComputerName, $iDesiredAccess)
Local $vRet = DllCall( "advapi32.dll", "handle", "OpenSCManager", "str", $sComputerName, "str", "ServicesActive", "dword", $iDesiredAccess )
If IsArray( $vRet ) Then _
Return $vRet[0]
Return Null
EndFunc ;==> OpenSCManager
Func _OpenService($hSCMan, $sServiceName, $iDesiredAccess)
Local $vRet = DllCall( "advapi32.dll", "handle", "OpenService", "handle", $hSCMan, "str", $sServiceName, "dword", $iDesiredAccess )
If IsArray( $vRet ) Then _
Return $vRet[0]
Return Null
EndFunc ;==> OpenService
Func _CloseServiceHandle($hSCObject)
Local $vRet = DllCall( "advapi32.dll", "int", "CloseServiceHandle", "handle", $hSCObject )
If IsArray( $vRet ) Then _
Return $vRet[0]
Return Null
EndFunc ;==> CloseServiceHandle
Func _GetServiceError($iType=0)
Local $aRet = DllCall("kernel32.dll", "long", "GetLastError")
$aRet[0] *= -1
If $iType Then $aRet = $aRet[0]
Return $aRet
EndFunc
Func _IsServiceFail($vRet)
Return ( IsInt( $vRet ) And ( $vRet < 0 ) )
EndFunc