net start service_name
Shell "C:\start.bat", vbHide
net stop service_name
OpenSCManager
OpenService (SERVICE_PAUSE_CONTINUE)
ControlService (SERVICE_CONTROL_PAUSE)
QueryServiceStatus в цикле пока не SERVICE_PAUSED
работа с хранилищем
ControlService (SERVICE_CONTROL_CONTINUE)
CloseServiceHandle (hService)
CloseServiceHandle (hManager)
hService это то, что возвращает Instal\CreateService
hManager это то, что возвращает OpenSCManager
hManager = OpenSCManager
Dim hManager As Long
Dim hService As Long
Dim tmp1 As Long
Dim tmp2 As Long
Dim tmp3 As SERVICE_STATUS
Public Declare Function OpenSCManager Lib "advapi32.dll" Alias "OpenSCManagerA" (ByVal lpMachineName As String, ByVal lpDatabaseName As String, ByVal dwDesiredAccess As Long) As Long
Public Declare Function OpenService Lib "advapi32.dll" Alias "OpenServiceA" (ByVal hSCManager As Long, ByVal lpServiceName As String, ByVal dwDesiredAccess As Long) As Long
Public Declare Function ControlService Lib "advapi32.dll" (ByVal hService As Long, ByVal dwControl As Long, lpServiceStatus As SERVICE_STATUS) As Long
Public Declare Function QueryServiceStatus Lib "advapi32.dll" (ByVal hService As Long, lpServiceStatus As SERVICE_STATUS) As Long
Public Declare Function CloseServiceHandle Lib "advapi32.dll" (ByVal hSCObject As Long) As Long
Public Type SERVICE_STATUS
dwServiceType As Long
dwCurrentState As Long
dwControlsAccepted As Long
dwWin32ExitCode As Long
dwServiceSpecificExitCode As Long
dwCheckPoint As Long
dwWaitHint As Long
End Type
Public Const SERVICE_ACCEPT_PAUSE_CONTINUE = &H2
Public Const SERVICE_ACCEPT_SHUTDOWN = &H4
Public Const SERVICE_ACCEPT_STOP = &H1
Public Const SERVICE_ACTIVE = &H1
Public Const SERVICE_CHANGE_CONFIG = &H2
Public Const SERVICE_CONTINUE_PENDING = &H5
Public Const SERVICE_CONTROL_CONTINUE = &H3
Public Const SERVICE_CONTROL_INTERROGATE = &H4
Public Const SERVICE_CONTROL_PAUSE = &H2
Public Const SERVICE_CONTROL_SHUTDOWN = &H5
Public Const SERVICE_CONTROL_STOP = &H1
Public Const SERVICE_ENUMERATE_DEPENDENTS = &H8
Public Const SERVICE_INACTIVE = &H2
Public Const SERVICE_INTERROGATE = &H80
Public Const SERVICE_NO_CHANGE = &HFFFF
Public Const SERVICE_PAUSE_CONTINUE = &H40
Public Const SERVICE_PAUSE_PENDING = &H6
Public Const SERVICE_PAUSED = &H7
Public Const SERVICE_QUERY_CONFIG = &H1
Public Const SERVICE_QUERY_STATUS = &H4
Public Const SERVICE_RUNNING = &H4
Public Const SERVICE_START = &H10
Public Const SERVICE_START_PENDING = &H2
Public Const SERVICE_STATE_ALL = (SERVICE_ACTIVE Or SERVICE_INACTIVE)
Public Const SERVICE_STOP = &H20
Public Const SERVICE_STOP_PENDING = &H3
Public Const SERVICE_STOPPED = &H1
Public Const SERVICE_USER_DEFINED_CONTROL = &H100
Public Const SERVICE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SERVICE_QUERY_CONFIG Or SERVICE_CHANGE_CONFIG Or SERVICE_QUERY_STATUS Or SERVICE_ENUMERATE_DEPENDENTS Or SERVICE_START Or SERVICE_STOP Or SERVICE_PAUSE_CONTINUE Or SERVICE_INTERROGATE Or SERVICE_USER_DEFINED_CONTROL)
hManager = OpenSCManager("", "", SERVICE_ALL_ACCESS)
hService = OpenService(hManager, "InCD Helper", SERVICE_ALL_ACCESS)
tmp1 = ControlService(hService, SERVICE_CONTROL_STOP, tmp3)
MsgBox "0"
'tmp2 = QueryServiceStatus
'QueryServiceStatus в цикле пока не SERVICE_PAUSED
'работа с хранилищем
tmp1 = ControlService(hManager, SERVICE_CONTROL_CONTINUE, tmp3)
CloseServiceHandle (hService)
CloseServiceHandle (hManager)
RetVal = Err.LastDllError
MsgBox Err.LastDllError
tmp1 = ControlService(hService, SERVICE_CONTROL_STOP, tmp3)
VVitafresh писал(а): Создаешь батник, в котором пишешь:...
- Код: Выделить всё
net start service_name
- Код: Выделить всё
Shell "C:\start.bat", vbHide
Shell "net start service_name", vbHide
Dim hManager As Long
Dim hService As Long
hManager = OpenSCManager("", SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS)
hService = OpenService(hManager, "Темы", SERVICE_ALL_ACCESS)
Shell "net stop ""Темы""", vbHide
kinrew писал(а):
- Код: Выделить всё
Dim hManager As Long
Dim hService As Long
hManager = OpenSCManager("", SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS)
hService = OpenService(hManager, "Темы", SERVICE_ALL_ACCESS)
Почему может возникать ошибка 1060 ERROR_SERVICE_DOES_NOT_EXIST после выполнения оператора OpenService, причём если написатьто всё нормально и служба останавливается?
- Код: Выделить всё
Shell "net stop ""Темы""", vbHide
Значения hManager = 2058248
hService = 0
Сейчас этот форум просматривают: AhrefsBot, Google-бот и гости: 35