Как включить\выключить Service

Программирование на Visual Basic, главный форум. Обсуждение тем программирования на VB 1—6.
Даже если вы плохо разбираетесь в VB и программировании вообще — тут вам помогут. В разумных пределах, конечно.
Правила форума
Темы, в которых будет сначала написано «что нужно сделать», а затем просьба «помогите», будут закрыты.
Читайте требования к создаваемым темам.
Max!
Постоялец
Постоялец
Аватара пользователя
 
Сообщения: 502
Зарегистрирован: 03.04.2003 (Чт) 22:08
Откуда: Литва

Как включить\выключить Service

Сообщение Max! » 15.02.2005 (Вт) 20:28

Доброго вам время суток. В Computer Management , затем Services and Applications , вот что мне нужно это програмным путём включить\выключить определённый Service ?. Прошу помощи .

:wink:
Max!

Amed
Алфизик
Алфизик
 
Сообщения: 5346
Зарегистрирован: 09.03.2003 (Вс) 9:26

Сообщение Amed » 15.02.2005 (Вт) 20:43

MSDN писал(а):StartService
The StartService function starts a service.

BOOL StartService(
SC_HANDLE hService, // handle of service
DWORD dwNumServiceArgs, // number of arguments
LPCTSTR *lpServiceArgVectors // array of argument strings
// string pointers
);

Parameters
hService
Handle to the service. This handle is returned by the OpenService or CreateService function, and it must have SERVICE_START access.
dwNumServiceArgs
Specifies the number of argument strings in the lpServiceArgVectors array. If lpServiceArgVectors is NULL, this parameter can be zero.
lpServiceArgVectors
Pointer to an array of pointers that point to null-terminated argument strings passed to a service. Driver services do not receive these arguments. If no arguments are passed to the service being started, this parameter can be NULL. The service accesses these arguments through its ServiceMain function. The first argument (argv[0]) is the name of the service by default, followed by the arguments, if any, in the lpServiceArgVectors array.
Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Errors
The following error codes can be set by the service control manager. Others can be set by the registry functions that are called by the service control manager.

Value Meaning
ERROR_ACCESS_DENIED The specified handle was not opened with SERVICE_START access.
ERROR_INVALID_HANDLE The specified handle is invalid.
ERROR_PATH_NOT_FOUND The service binary file could not be found.
ERROR_SERVICE_ALREADY_RUNNING An instance of the service is already running.
ERROR_SERVICE_DATABASE_LOCKED The database is locked.
ERROR_SERVICE_DEPENDENCY_DELETED The service depends on a service that does not exist or has been marked for deletion.
ERROR_SERVICE_DEPENDENCY_FAIL The service depends on another service that has failed to start.
ERROR_SERVICE_DISABLED The service has been disabled.
ERROR_SERVICE_LOGON_FAILED The service could not be logged on.
ERROR_SERVICE_MARKED_FOR_DELETE The service has been marked for deletion.
ERROR_SERVICE_NO_THREAD A thread could not be created for the service.
ERROR_SERVICE_REQUEST_TIMEOUT The service did not respond to the start request in a timely fashion.


Remarks
When a driver service is started, the StartService function does not return until the device driver has finished initializing.

When a Win32-based service is started, the service control manager spawns the service process, if necessary. If the specified service shares a process with other services, the required process may already exist. The StartService function does not wait for the first status update from the new service, because it can take a while. Instead, it returns when the service control manager receives notification from the service control dispatcher that the ServiceMain thread for this service was created successfully.

The service control manager sets the following default status values before returning from StartService:

Current state of the service is set to SERVICE_START_PENDING.
Controls accepted is set to none (zero).
The CheckPoint value is set to zero.
The WaitHint time is set to 2 seconds.
The calling process can determine if the new service has finished its initialization by calling the QueryServiceStatus function periodically to query the service's status.

A service cannot call StartService during initialization. The reason is that the service control manager locks the service control database during initialization, so a call to StartService will block. Once the service reports to the service control manager that it has successfully started, it can call StartService.

QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Unsupported.
Windows CE: Unsupported.
Header: Declared in winsvc.h.
Import Library: Use advapi32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT.

Max!
Постоялец
Постоялец
Аватара пользователя
 
Сообщения: 502
Зарегистрирован: 03.04.2003 (Чт) 22:08
Откуда: Литва

Сообщение Max! » 15.02.2005 (Вт) 22:10

Старт, стоп, пауза это я разобрался ! А вот если Service стоит Disabled или Manual как его врубить (Enable) ???

:wink:
Max!

Max!
Постоялец
Постоялец
Аватара пользователя
 
Сообщения: 502
Зарегистрирован: 03.04.2003 (Чт) 22:08
Откуда: Литва

Сообщение Max! » 17.02.2005 (Чт) 15:13

Help ! plz !

:wink:
Max!


Вернуться в Visual Basic 1–6

Кто сейчас на конференции

Сейчас этот форум просматривают: AhrefsBot и гости: 162

    TopList