网站首页  词典首页

请输入您要查询的函数:

 

术语 notifyservicestatuschange
释义 NotifyServiceStatusChange
语法:
C++
DWORD WINAPI NotifyServiceStatusChange(
__in SC_HANDLE hService,
__in DWORD dwNotifyMask,
__in PSERVICE_NOTIFY pNotifyBuffer
);
NotifyServiceStatusChange功能
使应用程序时收到通知指定的服务创建,删除或变更时,其地位。
参数
hService [in]
一个句柄,服务或服务控制管理器。句柄服务返回的OpenService或CreateService功能,必须有SERVICE_QUERY_STATUS访问权限。处理到服务控制管理器返回的OpenSCManager职能,必须有SC_MANAGER_ENUMERATE_SERVICE访问权限。有关更多信息,请参阅服务安全和访问权限。
只能有一个出色的通知每一项服务的要求。
dwNotifyMask [in]
的地位,应该报告的变化类型。此参数可以是一个或多个下列值。
ValueMeaning
SERVICE_NOTIFY_CREATED
0x00000080Report服务时,已创建。
该hService参数必须的句柄供应链管理。
SERVICE_NOTIFY_CONTINUE_PENDING
0x00000010Report服务时,要继续下去。
该hService参数必须是处理的服务。
SERVICE_NOTIFY_DELETE_PENDING
0x00000200Report当一个应用程序已指定在调用该服务的DeleteService函数。您的应用程序应该关闭任何处理的服务,以便它可以被删除。
该hService参数必须是处理的服务。
SERVICE_NOTIFY_DELETED
0x00000100Report服务时已被删除。应用程序不能收到此通知,如果它有一个打开句柄的服务。
该hService参数必须的句柄供应链管理。
SERVICE_NOTIFY_PAUSE_PENDING
0x00000020Report当服务暂停。
该hService参数必须是处理的服务。
SERVICE_NOTIFY_PAUSED
0x00000040Report时,该服务已暂停。
该hService参数必须是处理的服务。
SERVICE_NOTIFY_RUNNING
0x00000008Report当服务正在运行。
该hService参数必须是处理的服务。
SERVICE_NOTIFY_START_PENDING
0x00000002Report当服务正在启动。
该hService参数必须是处理的服务。
SERVICE_NOTIFY_STOP_PENDING
0x00000004Report当服务正在停止。
该hService参数必须是处理的服务。
SERVICE_NOTIFY_STOPPED
0x00000001Report时,该服务已停止。
该hService参数必须是处理的服务。
pNotifyBuffer [in]
一个 SERVICE_NOTIFY结构,它包含如到回调函数的指针通报信息,指针。这种结构必须保持有效,直到调用回调函数调用线程或取消的通知要求。
不要多次调用NotifyServiceStatusChange与直至自第一次调用回调函数的参数相同的缓冲区缓冲区或与第一份通知要求,完成已被取消。否则,也不能保证该缓冲区的回调函数将收到的版本。
Windows Vista的:在回调函数的地址必须是在一个加载的模块的地址范围。因此,回调函数不能被代码,在运行时产生的(如托管代码的JIT编译器生成的)或本机代码,在运行时解压缩。取消这项限制在Windows Server 2008和Windows Vista SP1的。
返回值
如果函数成功,返回值是ERROR_SUCCESS。如果该服务已被标记为删除,则返回值为ERROR_SERVICE_MARKED_FOR_DELETE和处理的服务必须关闭。如果服务的通知是落后的系统状态,该函数返回ERROR_SERVICE_NOTIFY_CLIENT_LAGGING。在这种情况下,客户应关闭的句柄供应链,打开一个新的处理,并再次调用这个函数。
如果函数失败,返回值是系统错误代码之一。
备注
该NotifyServiceStatusChange函数可用于接收有关服务应用程序的通知。它不能被用来接收有关司机服务的通知。
当服务状态的改变,系统调用的异步过程调用(APC)指定的回调函数排队调用线程。调用线程必须输入报警等待(例如,通过调用SleepEx函数)来接收通知。有关更多信息,请参阅异步过程调用。
函数调用的NotifyServiceStatusChange关于与THREAD_SET_CONTEXT访问权限调用线程的OpenThread功能。如果调用线程没有这种访问权限,NotifyServiceStatusChange失败。如果调用线程是假冒其他用户,它可能没有足够的权限来设置上下文。
这是更有效的调用NotifyServiceStatusChange从一个线程执行一个不是等待创建一个额外的线程。
后调用回调函数,调用者必须调用NotifyServiceStatusChange,获得额外的通知。请注意,在Windows API,包括NotifyServiceStatusChange和其他供应链管理功能,使用某些功能,远程过程调用(RPC),这些功能可能执行的可报警等待操作,因此他们并不安全调用内部的回调函数。相反,应该保存回调函数参数的通知,并执行回调以外的任何额外工作。
如果服务在所要求的国家之一,是由于第一次调用此函数,调用回调函数立即。如果服务状态并没有因下一次功能是相同的服务和国家,回调函数调用调用改变的不马上回调函数调用下一次服务进入被请求国。
要取消未通知,关闭该服务使用CloseServiceHandle处理功能。 CloseServiceHandle成功后,不再通知装甲运兵车将被排队。如果不关闭服务等待处理或生成的APC,内存泄漏可能发生调用线程退出。
如果调用线程处于DLL和卸载DLL是线程之前收到通知或电话CloseServiceHandle重要的是,通知将导致不可预知的结果,并可能导致进程停止响应。
要求:
client最低支持Vista
server最低支持 Windows Server 2008
HeaderWinsvc.h(头文件:winuser.h)
LibraryAdvapi32.lib
DLLAdvapi32.dll
Unicode和ANSI namesNotifyServiceStatusChangeW(Unicode)和NotifyServiceStatusChangeA(ANSI)的
参见
服务函数
SERVICE_NOTIFY
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==NotifyServiceStatusChange Function
Enables an application to receive notification when the specified service is created or deleted or when its status changes.
Syntax
C++
DWORD WINAPI NotifyServiceStatusChange(
__in SC_HANDLE hService,
__in DWORD dwNotifyMask,
__in PSERVICE_NOTIFY pNotifyBuffer
);
Parameters
hService [in]
A handle to the service or the service control manager. Handles to services are returned by the OpenService or CreateService function and must have the SERVICE_QUERY_STATUS access right. Handles to the service control manager are returned by the OpenSCManager function and must have the SC_MANAGER_ENUMERATE_SERVICE access right. For more information, see Service Security and Access Rights .
There can only be one outstanding notification request per service.
dwNotifyMask [in]
The type of status changes that should be reported. This parameter can be one or more of the following values.
ValueMeaning
SERVICE_NOTIFY_CREATED
0x00000080Report when the service has been created.
The hService parameter must be a handle to the SCM.
SERVICE_NOTIFY_CONTINUE_PENDING
0x00000010Report when the service is about to continue.
The hService parameter must be a handle to the service.
SERVICE_NOTIFY_DELETE_PENDING
0x00000200Report when an application has specified the service in a call to the DeleteService function. Your application should close any handles to the service so it can be deleted.
The hService parameter must be a handle to the service.
SERVICE_NOTIFY_DELETED
0x00000100Report when the service has been deleted. An application cannot receive this notification if it has an open handle to the service.
The hService parameter must be a handle to the SCM.
SERVICE_NOTIFY_PAUSE_PENDING
0x00000020Report when the service is pausing.
The hService parameter must be a handle to the service.
SERVICE_NOTIFY_PAUSED
0x00000040Report when the service has paused.
The hService parameter must be a handle to the service.
SERVICE_NOTIFY_RUNNING
0x00000008Report when the service is running.
The hService parameter must be a handle to the service.
SERVICE_NOTIFY_START_PENDING
0x00000002Report when the service is starting.
The hService parameter must be a handle to the service.
SERVICE_NOTIFY_STOP_PENDING
0x00000004Report when the service is stopping.
The hService parameter must be a handle to the service.
SERVICE_NOTIFY_STOPPED
0x00000001Report when the service has stopped.
The hService parameter must be a handle to the service.

pNotifyBuffer [in]
A pointer to a SERVICE_NOTIFY structure that contains notification information, such as a pointer to the callback function. This structure must remain valid until the callback function is invoked or the calling thread cancels the notification request.
Do not make multiple calls to NotifyServiceStatusChange with the same buffer parameter until the callback function from the first call has finished with the buffer or the first notification request has been canceled. Otherwise, there is no guarantee which version of the buffer the callback function will receive.
Windows Vista: The address of the callback function must be within the address range of a loaded module. Therefore, the callback function cannot be code that is generated at run time (such as managed code generated by the JIT compiler) or native code that is decompressed at run time. This restriction was removed in Windows Server 2008 and Windows Vista with SP1.
Return Value
If the function succeeds, the return value is ERROR_SUCCESS. If the service has been marked for deletion, the return value is ERROR_SERVICE_MARKED_FOR_DELETE and the handle to the service must be closed. If service notification is lagging too far behind the system state, the function returns ERROR_SERVICE_NOTIFY_CLIENT_LAGGING. In this case, the client should close the handle to the SCM, open a new handle, and call this function again.
If the function fails, the return value is one of the system error codes .
Remarks
The NotifyServiceStatusChange function can be used to receive notifications about service applications. It cannot be used to receive notifications about driver services.
When the service status changes, the system invokes the specified callback function as an asynchronous procedure call (APC) queued to the calling thread. The calling thread must enter an alertable wait (for example, by calling the SleepEx function) to receive notification. For more information, see Asynchronous Procedure Calls .
The NotifyServiceStatusChange function calls the OpenThread function on the calling thread with the THREAD_SET_CONTEXT access right. If the calling thread does not have this access right, NotifyServiceStatusChange fails. If the calling thread is impersonating another user, it may not have sufficient permission to set context.
It is more efficient to call NotifyServiceStatusChange from a thread that performs a wait than to create an additional thread.
After the callback function is invoked, the caller must call NotifyServiceStatusChange to receive additional notifications. Note that certain functions in the Windows API, including NotifyServiceStatusChange and other SCM functions, use remote procedure calls (RPC); these functions might perform an alertable wait operation, so they are not safe to call from within the callback function. Instead, the callback function should save the notification parameters and perform any additional work outside the callback.
If the service is in one of the requested states upon the first call to this function, the callback function is invoked immediately. If the service state has not changed by the next time the function is called with the same service and state, the callback function is not invoked immediately; the callback function is invoked the next time the service enters the requested state.
To cancel outstanding notifications, close the service handle using the CloseServiceHandle function. After CloseServiceHandle succeeds, no more notification APCs will be queued. If the calling thread exits without closing the service handle or waiting until the APC is generated, a memory leak can occur.
Important If the calling thread is in a DLL and the DLL is unloaded before the thread receives the notification or calls CloseServiceHandle, the notification will cause unpredictable results and might cause the process to stop responding.
Requirements
Minimum supported clientWindows Vista
Minimum supported serverWindows Server 2008
HeaderWinsvc.h (include Windows.h)
LibraryAdvapi32.lib
DLLAdvapi32.dll
Unicode and ANSI namesNotifyServiceStatusChangeW (Unicode) and NotifyServiceStatusChangeA (ANSI)
See Also
Service Functions
SERVICE_NOTIFY
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms684276(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 11:32:01