网站首页  词典首页

请输入您要查询的函数:

 

术语 netalertraise
释义 NetAlertRaise
语法:
C++
NET_API_STATUS NetAlertRaise(
__in LPCWSTR AlertEventName,
__in LPVOID Buffer,
__in DWORD BufferSize
);
NetAlertRaise功能
[此功能不支持作为Windows Vista,因为Alerter服务不支持。]
该NetAlertRaise函数通知所有登记的客户当某个事件发生。
为了简化发送警告消息,您可以调用扩展功能NetAlertRaiseEx代替。 NetAlertRaiseEx并不要求您指定一个STD_ALERT结构。
参数
AlertEventName [in]
一个字符串常量,指定警报类(警戒型),以提高指针。此参数可以是下列预定义的值,或用户定义的网络应用警报类。对于警报事件名称可以是任何文本字符串。
NameMeaning
ALERT_ADMIN_EVENTAn管理员的干预是必需的。
ALERT_ERRORLOG_EVENTAn条目被添加到错误日志。
ALERT_MESSAGE_EVENTA用户或应用程序收到广播消息。
ALERT_PRINT_EVENTA打印作业完成或打印错误。
ALERT_USER_EVENTAn应用或资源的使用。
缓冲区 [in]
一个数据指针发送到客户端的中断消息听。这些数据应首先一个固定长度的STD_ALERT在一个ADMIN_OTHER_INFO,ERRLOG_OTHER_INFO,PRINT_OTHER_INFO,或USER_OTHER_INFO结构的其他信息资料后结构。最后,缓冲区应该包括任何所需的可变长度的信息。有关详细信息,请参见下面的备注部分的代码示例。
调用应用程序必须分配和释放所有结构和可变数据存储器。有关更多信息,请参阅网络管理功能的缓冲器。
缓冲区大小 [in]
大小,以字节为单位的消息缓冲区。
返回值
如果函数成功,返回值是NERR_Success。
如果函数失败,返回值是一个系统错误代码和一个可以是下面的错误代码之一。对于所有可能的错误代码的列表,请参见系统错误代码。
返回codeDescription
ERROR_INVALID_PARAMETERA参数不正确。返回此错误,如果AlertEventName参数为NULL或空字符串,缓冲区参数为NULL,或者缓冲区大小参数比STD_ALERT结构加上额外的消息数据结构的固定大小的大小。
ERROR_NOT_SUPPORTEDThe不支持请求。返回此错误在Windows Vista,后来由于Alerter服务不支持。
备注
没有特殊组成员必须成功地执行NetAlertRaise功能。
Alerter服务必须在客户端计算机上运行时调用NetAlertRaise函数,或函数失败,ERROR_FILE_NOT_FOUND。
实例
下面的代码示例演示如何提高调用NetAlertRaise函数并指定STD_ALERT和ADMIN_OTHER_INFO结构管理警报。首先,样本计算邮件的缓冲区的大小。然后分配,以GlobalAlloc函数调用的缓冲区。赋值的代码对STD_ALERT和缓冲区的ADMIN_OTHER_INFO部分成员。示例检索指针ADMIN_OTHER_INFO结构调用ALERT_OTHER_INFO宏。它还检索一个指向缓冲区的可变数据部分通过调用ALERT_VAR_DATA宏。最后,该代码示例的释放,以GlobalFree函数调用的缓冲区分配内存。
#ifndef UNICODE
#define UNICODE
#endif
#pragma comment(lib, "netapi32.lib")
#include
#include
#include
#include
const int ALERT_VAR_DATA_SIZE = 216;
int wmain(int argc, wchar_t *argv[])
{
int nBufferSize;
LPVOID pAlertOtherInfo;
PSTD_ALERT pStdAlert; // STD_ALERT structure
PADMIN_OTHER_INFO pAdminOtherInfo; // ADMIN_OTHER_INFO structure
LPVOID pVarData;
time_t now;
DWORD dwResult;
//
// Check command line arguments.
//
if (argc != 2)
{
fwprintf(stderr, L"Usage: %s LogFileName\\n", argv[0]);
exit(1);
}
// Calculate the buffer size;
// then allocate the memory for the buffer.
//
nBufferSize = sizeof(STD_ALERT) + ALERT_VAR_DATA_SIZE;
pAlertOtherInfo = (LPVOID) GlobalAlloc(GPTR, nBufferSize);
if (pAlertOtherInfo == NULL)
{
fwprintf(stderr, L"Unable to allocate memory\\n");
exit(1);
}
//
// Assign values to the STD_ALERT portion of the buffer.
// (This is required when you call NetAlertRaise.)
//
pStdAlert = (PSTD_ALERT)pAlertOtherInfo;
time( &now );
pStdAlert->alrt_timestamp = (DWORD)now;
wcscpy_s(pStdAlert->alrt_eventname, EVLEN + 1, ALERT_ADMIN_EVENT);
wcscpy_s(pStdAlert->alrt_servicename, SNLEN + 1, argv[0]);
//
// Retrieve the pointer to the ADMIN_OTHER_INFO structure
// that follows the STD_ALERT portion of the buffer.
// Do this by calling the ALERT_OTHER_INFO macro.
//
pAdminOtherInfo = (PADMIN_OTHER_INFO)ALERT_OTHER_INFO(pAlertOtherInfo);
//
// Assign values to the ADMIN_OTHER_INFO structure.
//
pAdminOtherInfo->alrtad_numstrings = 1;
//
// Error 2377, NERR_LogOverflow, indicates
// a log file is full.
//
pAdminOtherInfo->alrtad_errcode = 2377;
//
// Retrieve the pointer to the variable data portion
// of the buffer by calling the ALERT_VAR_DATA macro.
//
pVarData = (LPTSTR)ALERT_VAR_DATA(pAdminOtherInfo);
//
// Supply the log file name for error 2377.
//
wcsncpy_s((wchar_t*) pVarData, ALERT_VAR_DATA_SIZE/2,
argv[1],
ALERT_VAR_DATA_SIZE/2 );
//
// Send an administrative alert by calling the
// NetAlertRaise function.
//
dwResult = NetAlertRaise(ALERT_ADMIN_EVENT,
pAlertOtherInfo,
nBufferSize);
//
// Display the results of the function call.
//
if (dwResult != NERR_Success)
wprintf(L"NetAlertRaise failed: %d\\n", dwResult);
else
wprintf(L"Administrative alert raised successfully.\\n");
//
// Free the allocated memory.
//
GlobalFree(pAlertOtherInfo);
return (dwResult);
}
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
客户supportWindows的高端XP
服务器supportWindows低端服务器2003
HeaderLmalert.h(包括Lm.h)
LibraryNetapi32.lib
DLLNetapi32.dll
参见
网络管理概述
网络管理功能
警报功能
ADMIN_OTHER_INFO
ERRLOG_OTHER_INFO
NetAlertRaiseEx
PRINT_OTHER_INFO
STD_ALERT
USER_OTHER_INFO
ALERT_OTHER_INFO
ALERT_VAR_DATA
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月13日
==英文原文==NetAlertRaise Function
[This function is not supported as of Windows Vista because the alerter service is not supported.]
The NetAlertRaise function notifies all registered clients when a particular event occurs.
To simplify sending an alert message, you can call the extended function NetAlertRaiseEx instead. NetAlertRaiseEx does not require that you specify a STD_ALERT structure.
Syntax
C++
NET_API_STATUS NetAlertRaise(
__in LPCWSTR AlertEventName,
__in LPVOID Buffer,
__in DWORD BufferSize
);
Parameters
AlertEventName [in]
A pointer to a constant string that specifies the alert class (type of alert) to raise. This parameter can be one of the following predefined values, or a user-defined alert class for network applications. The event name for an alert can be any text string.
NameMeaning
ALERT_ADMIN_EVENTAn administrator's intervention is required.
ALERT_ERRORLOG_EVENTAn entry was added to the error log.
ALERT_MESSAGE_EVENTA user or application received a broadcast message.
ALERT_PRINT_EVENTA print job completed or a print error occurred.
ALERT_USER_EVENTAn application or resource was used.

Buffer [in]
A pointer to the data to send to the clients listening for the interrupting message. The data should begin with a fixed-length STD_ALERT structure followed by additional message data in one ADMIN_OTHER_INFO , ERRLOG_OTHER_INFO , PRINT_OTHER_INFO , or USER_OTHER_INFO structure. Finally, the buffer should include any required variable-length information. For more information, see the code sample in the following Remarks section.
The calling application must allocate and free the memory for all structures and variable data. For more information, see Network Management Function Buffers .
BufferSize [in]
The size, in bytes, of the message buffer.
Return Value
If the function succeeds, the return value is NERR_Success.
If the function fails, the return value is a system error code and a can be one of the following error codes. For a list of all possible error codes, see System Error Codes .
Return codeDescription
ERROR_INVALID_PARAMETERA parameter is incorrect. This error is returned if the AlertEventName parameter is NULL or an empty string, the Buffer parameter is NULL, or the BufferSize parameter is less than the size of the STD_ALERT structure plus the fixed size for the additional message data structure.
ERROR_NOT_SUPPORTEDThe request is not supported. This error is returned on Windows Vista and later since the Alerter service is not supported.

Remarks
No special group membership is required to successfully execute the NetAlertRaise function.
The alerter service must be running on the client computer when you call the NetAlertRaise function, or the function fails with ERROR_FILE_NOT_FOUND.
Examples
The following code sample demonstrates how to raise an administrative alert by calling the NetAlertRaise function and specifying STD_ALERT and ADMIN_OTHER_INFO structures. First, the sample calculates the size of the message buffer. Then it allocates the buffer with a call to the GlobalAlloc function. The code assigns values to the members of the STD_ALERT and the ADMIN_OTHER_INFO portions of the buffer. The sample retrieves a pointer to the ADMIN_OTHER_INFO structure by calling the ALERT_OTHER_INFO macro. It also retrieves a pointer to the variable data portion of the buffer by calling the ALERT_VAR_DATA macro. Finally, the code sample frees the memory allocated for the buffer with a call to the GlobalFree function.
#ifndef UNICODE
#define UNICODE
#endif
#pragma comment(lib, "netapi32.lib")
#include
#include
#include
#include
const int ALERT_VAR_DATA_SIZE = 216;
int wmain(int argc, wchar_t *argv[])
{
int nBufferSize;
LPVOID pAlertOtherInfo;
PSTD_ALERT pStdAlert; // STD_ALERT structure
PADMIN_OTHER_INFO pAdminOtherInfo; // ADMIN_OTHER_INFO structure
LPVOID pVarData;
time_t now;
DWORD dwResult;
//
// Check command line arguments.
//
if (argc != 2)
{
fwprintf(stderr, L"Usage: %s LogFileName\\n", argv[0]);
exit(1);
}
// Calculate the buffer size;
// then allocate the memory for the buffer.
//
nBufferSize = sizeof(STD_ALERT) + ALERT_VAR_DATA_SIZE;
pAlertOtherInfo = (LPVOID) GlobalAlloc(GPTR, nBufferSize);
if (pAlertOtherInfo == NULL)
{
fwprintf(stderr, L"Unable to allocate memory\\n");
exit(1);
}
//
// Assign values to the STD_ALERT portion of the buffer.
// (This is required when you call NetAlertRaise.)
//
pStdAlert = (PSTD_ALERT)pAlertOtherInfo;
time( &now );
pStdAlert->alrt_timestamp = (DWORD)now;
wcscpy_s(pStdAlert->alrt_eventname, EVLEN + 1, ALERT_ADMIN_EVENT);
wcscpy_s(pStdAlert->alrt_servicename, SNLEN + 1, argv[0]);
//
// Retrieve the pointer to the ADMIN_OTHER_INFO structure
// that follows the STD_ALERT portion of the buffer.
// Do this by calling the ALERT_OTHER_INFO macro.
//
pAdminOtherInfo = (PADMIN_OTHER_INFO)ALERT_OTHER_INFO(pAlertOtherInfo);
//
// Assign values to the ADMIN_OTHER_INFO structure.
//
pAdminOtherInfo->alrtad_numstrings = 1;
//
// Error 2377, NERR_LogOverflow, indicates
// a log file is full.
//
pAdminOtherInfo->alrtad_errcode = 2377;
//
// Retrieve the pointer to the variable data portion
// of the buffer by calling the ALERT_VAR_DATA macro.
//
pVarData = (LPTSTR)ALERT_VAR_DATA(pAdminOtherInfo);
//
// Supply the log file name for error 2377.
//
wcsncpy_s((wchar_t*) pVarData, ALERT_VAR_DATA_SIZE/2,
argv[1],
ALERT_VAR_DATA_SIZE/2 );
//
// Send an administrative alert by calling the
// NetAlertRaise function.
//
dwResult = NetAlertRaise(ALERT_ADMIN_EVENT,
pAlertOtherInfo,
nBufferSize);
//
// Display the results of the function call.
//
if (dwResult != NERR_Success)
wprintf(L"NetAlertRaise failed: %d\\n", dwResult);
else
wprintf(L"Administrative alert raised successfully.\\n");
//
// Free the allocated memory.
//
GlobalFree(pAlertOtherInfo);
return (dwResult);
}
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
End of client supportWindows XP
End of server supportWindows Server 2003
HeaderLmalert.h (include Lm.h)
LibraryNetapi32.lib
DLLNetapi32.dll
See Also
Network Management Overview
Network Management Functions
Alert Functions
ADMIN_OTHER_INFO
ERRLOG_OTHER_INFO
NetAlertRaiseEx
PRINT_OTHER_INFO
STD_ALERT
USER_OTHER_INFO
ALERT_OTHER_INFO
ALERT_VAR_DATA
Send comments about this topic to Microsoft
Build date: 8/13/2009
==原始网址==http://msdn.microsoft.com/en-us/library/aa370297(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:26:43