网站首页  词典首页

请输入您要查询的函数:

 

术语 netalertraiseex
释义 NetAlertRaiseEx
语法:
C++
NET_API_STATUS NetAlertRaiseEx(
__in LPCWSTR AlertEventName,
__in LPVOID VariableInfo,
__in DWORD VariableInfoSize,
__in LPCWSTR ServiceName
);
NetAlertRaiseEx功能
[此功能不支持作为Windows Vista,因为Alerter服务不支持。]
该NetAlertRaiseEx函数通知所有登记的客户当某个事件发生。您可以把这扩展功能,以简化警报消息发送,因为NetAlertRaiseEx并不要求您指定一个STD_ALERT结构。
参数
AlertEventName [in]
一个字符串常量,指定警报类(警戒型),以提高指针。此参数可以是下列预定义的值,或用户定义的网络应用警报类。 (为警报事件名称可以是任何文本字符串。)
NameMeaning
ALERT_ADMIN_EVENTAn管理员的干预是必需的。
ALERT_ERRORLOG_EVENTAn条目被添加到错误日志。
ALERT_MESSAGE_EVENTA用户或应用程序收到广播消息。
ALERT_PRINT_EVENTA打印作业完成或打印错误。
ALERT_USER_EVENTAn应用或资源的使用。
VariableInfo [in]
一个数据指针发送到客户端的中断消息听。这些数据应包括一名ADMIN_OTHER_INFO,ERRLOG_OTHER_INFO,PRINT_OTHER_INFO,或USER_OTHER_INFO结构任何所需的可变长度的信息之后。有关详细信息,请参见下面的备注部分的代码示例。
调用应用程序必须分配和释放所有结构和可变数据存储器。有关更多信息,请参阅网络管理功能的缓冲器。
VariableInfoSize [in]
在缓冲区中的变量信息的字节数指向的VariableInfo参数。
服务名称 [in]
一个字符串常量,指定服务的名称,提高中断消息的指针。
返回值
如果函数成功,返回值是NERR_Success。
如果函数失败,返回值是一个系统错误代码和一个可以是下面的错误代码之一。对于所有可能的错误代码的列表,请参见系统错误代码。
返回codeDescription
ERROR_INVALID_PARAMETERA参数不正确。返回此错误,如果AlertEventName参数为NULL或空字符串,将ServiceName参数是NULL或空字符串,VariableInfo参数为NULL,或者VariableInfoSize参数大于512减去STD_ALERT结构的大小。
ERROR_NOT_SUPPORTEDThe不支持请求。返回此错误在Windows Vista,后来由于Alerter服务不支持。
备注
没有特殊组成员必须成功地执行NetAlertRaiseEx功能。
Alerter服务必须在客户端计算机上运行时调用NetAlertRaiseEx函数,或函数失败,ERROR_FILE_NOT_FOUND。
实例
下面的代码示例演示了如何提高打断以下类型的消息(警报)通过调用NetAlertRaiseEx功能:
通过指定一个ADMIN_OTHER_INFO结构管理警报
由指定PRINT_OTHER_INFO结构打印警报
由指定USER_OTHER_INFO结构用户警惕
在每个实例的代码赋值相关警报信息结构的成员。在此之后,样本检索指针的消息缓冲区后面通过调用ALERT_VAR_DATA宏观结构的一部分。该代码还填补了变数,在这部分的缓冲区长度的字符串。最后,该示例调用NetAlertRaiseEx发送警报。
请注意,调用应用程序必须分配和释放所有结构和警报消息缓冲区长度可变的数据存储器。
通过一个用户定义的用户结构和有效的警报字符串,您必须创建一个事件消息文件并连接您的应用程序。您还必须在登记在EventLog的部分EventMessageFile注册表子项申请。如果您没有注册的申请,提醒用户的信息将包含您在可变长度的字符串,按照USER_OTHER_INFO结构通过。欲了解更多有关EventMessageFile信息,请参阅事件日志记录。
#ifndef UNICODE
#define UNICODE
#endif
#pragma comment(lib, "netapi32.lib")
#include
#include
#include
#include
//
// Define default strings.
//
#define PROGRAM_NAME TEXT("NETALRT")
#define szComputerName TEXT("\\\\\\\\TESTCOMPUTER")
#define szUserName TEXT("TEST")
#define szQueueName TEXT("PQUEUE")
#define szDestName TEXT("MYPRINTER")
#define szStatus TEXT("OK")
//
// Define structure sizes.
//
#define VAREDSIZE 312 // maximum size of the variable length message
char buff[VAREDSIZE];
//
int main()
{
time_t now;
PADMIN_OTHER_INFO pAdminInfo; // ADMIN_OTHER_INFO structure
PPRINT_OTHER_INFO pPrintInfo; // PRINT_OTHER_INFO structure
PUSER_OTHER_INFO pUserInfo; // USER_OTHER_INFO structure
TCHAR *p;
DWORD dwResult;
time( &now ); // Retrieve the current time to print it later.
//
// Sending an administrative alert
//
// Assign values to the members of the ADMIN_OTHER_INFO structure.
//
pAdminInfo = (PADMIN_OTHER_INFO) buff;
ZeroMemory(pAdminInfo, VAREDSIZE);
//
// Error 2377, NERR_LogOverflow, indicates
// a log file is full.
//
pAdminInfo->alrtad_errcode = 2377;
pAdminInfo->alrtad_numstrings = 1;
//
// Retrieve a pointer to the variable data portion at the
// end of the buffer by calling the ALERT_VAR_DATA macro.
//
p = (LPTSTR) ALERT_VAR_DATA(pAdminInfo);
//
// Fill in the variable-length, concatenated strings
// that follow the ADMIN_OTHER_INFO structure. These strings
// will be written to the message log.
//
wcscpy_s(p,VAREDSIZE/2, TEXT("'C:\\\\MYLOG.TXT'"));
//
// Call the NetAlertRaiseEx function to raise the
// administrative alert.
//
dwResult = NetAlertRaiseEx(ALERT_ADMIN_EVENT, pAdminInfo, 255 , TEXT("MYSERVICE"));
//
// Display the results of the function call.
//
if (dwResult != NERR_Success)
{
wprintf(L"NetAlertRaiseEx failed: %d\\n", dwResult);
return -1;
}
else
wprintf(L"Administrative alert raised successfully.\\n");

//
// Sending a print alert
//
// Assign values to the members of the PRINT_OTHER_INFO structure.
//
pPrintInfo = (PPRINT_OTHER_INFO) buff;
ZeroMemory(pPrintInfo, VAREDSIZE);
pPrintInfo->alrtpr_jobid = 5457;
pPrintInfo->alrtpr_status = 0;
pPrintInfo->alrtpr_submitted = now;
pPrintInfo->alrtpr_size = 1000;
//
// Retrieve a pointer to the variable data portion at the
// end of the buffer by calling the ALERT_VAR_DATA macro.
//
p = (LPTSTR) ALERT_VAR_DATA(pPrintInfo);
//
// Fill in the variable-length, concatenated strings
// that follow the PRINT_OTHER_INFO structure.
//
wcscpy_s(p, VAREDSIZE/2, szComputerName); // computername
p += lstrlen(p) + 1;
wcscpy_s(p, (VAREDSIZE/2)-wcslen(szComputerName)-1, szUserName); // username
p += lstrlen(p) + 1;
wcscpy_s(p, (VAREDSIZE/2)-wcslen(szComputerName)-wcslen(szUserName)-2,
szQueueName); // printer queuename
p += lstrlen(p) + 1;
wcscpy_s(p, (VAREDSIZE/2)-wcslen(szComputerName)-wcslen(szUserName)-wcslen(szQueueName)-3,
szDestName); // destination or printer name (optional)
p += lstrlen(p) + 1;
wcscpy_s(p, (VAREDSIZE/2)-wcslen(szComputerName)-wcslen(szUserName)-wcslen(szQueueName)
- wcslen(szDestName)-4, szStatus); // status of the print job (optional)
//
// Call the NetAlertRaiseEx function to raise the
// print alert.
//
dwResult = NetAlertRaiseEx(ALERT_PRINT_EVENT, pPrintInfo, VAREDSIZE, TEXT("MYSERVICE"));
//
// Display the results of the function call.
//
if (dwResult != NERR_Success)
{
wprintf(L"NetAlertRaiseEx failed: %d\\n", dwResult);
return -1;
}
else
wprintf(L"Print alert raised successfully.\\n");

//
// Sending a user alert
//
// Assign values to the members of the USER_OTHER_INFO structure.
//
pUserInfo = (PUSER_OTHER_INFO) buff;
ZeroMemory(pUserInfo, VAREDSIZE);
pUserInfo->alrtus_errcode = -1;
pUserInfo->alrtus_numstrings = 1;
//
// Retrieve a pointer to the variable data portion at the
// end of the buffer by calling the ALERT_VAR_DATA macro.
//
p = (LPTSTR) ALERT_VAR_DATA(pUserInfo);
//
// Fill in the variable-length, concatenated strings
// that follow the USER_OTHER_INFO structure.
//
wcscpy_s(p,(VAREDSIZE/2), TEXT("C:\\\\USERLOG.TXT"));
p += lstrlen(p) + 1;
wcscpy_s(p, (VAREDSIZE/2) - wcslen(TEXT("C:\\\\USERLOG.TXT"))-1, szUserName);
//
// Call the NetAlertRaiseEx function to raise the
// user alert.
//
dwResult = NetAlertRaiseEx(ALERT_USER_EVENT, pUserInfo, VAREDSIZE, TEXT("MYSERVICE"));
//
// Display the results of the function call.
//
if (dwResult != NERR_Success)
{
wprintf(L"NetAlertRaiseEx failed: %d\\n", dwResult);
return -1;
}
else
wprintf(L"User alert raised successfully.\\n");
return(dwResult);
}
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
客户supportWindows的高端XP
服务器supportWindows低端服务器2003
HeaderLmalert.h(包括Lm.h)
LibraryNetapi32.lib
DLLNetapi32.dll
参见
网络管理概述
网络管理功能
警报功能
NetAlertRaise
ADMIN_OTHER_INFO
ERRLOG_OTHER_INFO
PRINT_OTHER_INFO
USER_OTHER_INFO
ALERT_VAR_DATA
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月13日
==英文原文==NetAlertRaiseEx Function
[This function is not supported as of Windows Vista because the alerter service is not supported.]
The NetAlertRaiseEx function notifies all registered clients when a particular event occurs. You can call this extended function to simplify the sending of an alert message because NetAlertRaiseEx does not require that you specify a STD_ALERT structure.
Syntax
C++
NET_API_STATUS NetAlertRaiseEx(
__in LPCWSTR AlertEventName,
__in LPVOID VariableInfo,
__in DWORD VariableInfoSize,
__in LPCWSTR ServiceName
);
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.

VariableInfo [in]
A pointer to the data to send to the clients listening for the interrupting message. The data should consist of one ADMIN_OTHER_INFO , ERRLOG_OTHER_INFO , PRINT_OTHER_INFO , or USER_OTHER_INFO structure followed by 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 .
VariableInfoSize [in]
The number of bytes of variable information in the buffer pointed to by the VariableInfo parameter.
ServiceName [in]
A pointer to a constant string that specifies the name of the service raising the interrupting message.
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 ServiceName parameter is NULL or an empty string, the VariableInfo parameter is NULL, or the VariableInfoSize parameter is greater than 512 minus the size of the STD_ALERT 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 NetAlertRaiseEx function.
The alerter service must be running on the client computer when you call the NetAlertRaiseEx function, or the function fails with ERROR_FILE_NOT_FOUND.
Examples
The following code sample demonstrates how to raise the following types of interrupting messages (alerts) by calling the NetAlertRaiseEx function:
An administrative alert by specifying an ADMIN_OTHER_INFO structure
A print alert by specifying a PRINT_OTHER_INFO structure
A user alert by specifying a USER_OTHER_INFO structure
In each instance the code assigns values to the members of the relevant alert information structure. Following this, the sample retrieves a pointer to the portion of the message buffer that follows the structure by calling the ALERT_VAR_DATA macro. The code also fills in the variable-length strings in this portion of the buffer. Finally, the sample calls NetAlertRaiseEx to send the alert.
Note that the calling application must allocate and free the memory for all structures and variable-length data in an alert message buffer.
To pass a user-defined structure and valid strings in a user alert, you must create an event message file and link it with your application. You must also register the application in the EventMessageFile subkey in the EventLog section of the registry. If you do not register the application, the user alert will contain the information you pass in the variable-length strings that follow the USER_OTHER_INFO structure. For more information about EventMessageFile, see Event Logging .
#ifndef UNICODE
#define UNICODE
#endif
#pragma comment(lib, "netapi32.lib")
#include
#include
#include
#include
//
// Define default strings.
//
#define PROGRAM_NAME TEXT("NETALRT")
#define szComputerName TEXT("\\\\\\\\TESTCOMPUTER")
#define szUserName TEXT("TEST")
#define szQueueName TEXT("PQUEUE")
#define szDestName TEXT("MYPRINTER")
#define szStatus TEXT("OK")
//
// Define structure sizes.
//
#define VAREDSIZE 312 // maximum size of the variable length message
char buff[VAREDSIZE];
//
int main()
{
time_t now;
PADMIN_OTHER_INFO pAdminInfo; // ADMIN_OTHER_INFO structure
PPRINT_OTHER_INFO pPrintInfo; // PRINT_OTHER_INFO structure
PUSER_OTHER_INFO pUserInfo; // USER_OTHER_INFO structure
TCHAR *p;
DWORD dwResult;
time( &now ); // Retrieve the current time to print it later.
//
// Sending an administrative alert
//
// Assign values to the members of the ADMIN_OTHER_INFO structure.
//
pAdminInfo = (PADMIN_OTHER_INFO) buff;
ZeroMemory(pAdminInfo, VAREDSIZE);
//
// Error 2377, NERR_LogOverflow, indicates
// a log file is full.
//
pAdminInfo->alrtad_errcode = 2377;
pAdminInfo->alrtad_numstrings = 1;
//
// Retrieve a pointer to the variable data portion at the
// end of the buffer by calling the ALERT_VAR_DATA macro.
//
p = (LPTSTR) ALERT_VAR_DATA(pAdminInfo);
//
// Fill in the variable-length, concatenated strings
// that follow the ADMIN_OTHER_INFO structure. These strings
// will be written to the message log.
//
wcscpy_s(p,VAREDSIZE/2, TEXT("'C:\\\\MYLOG.TXT'"));
//
// Call the NetAlertRaiseEx function to raise the
// administrative alert.
//
dwResult = NetAlertRaiseEx(ALERT_ADMIN_EVENT, pAdminInfo, 255 , TEXT("MYSERVICE"));
//
// Display the results of the function call.
//
if (dwResult != NERR_Success)
{
wprintf(L"NetAlertRaiseEx failed: %d\\n", dwResult);
return -1;
}
else
wprintf(L"Administrative alert raised successfully.\\n");

//
// Sending a print alert
//
// Assign values to the members of the PRINT_OTHER_INFO structure.
//
pPrintInfo = (PPRINT_OTHER_INFO) buff;
ZeroMemory(pPrintInfo, VAREDSIZE);
pPrintInfo->alrtpr_jobid = 5457;
pPrintInfo->alrtpr_status = 0;
pPrintInfo->alrtpr_submitted = now;
pPrintInfo->alrtpr_size = 1000;
//
// Retrieve a pointer to the variable data portion at the
// end of the buffer by calling the ALERT_VAR_DATA macro.
//
p = (LPTSTR) ALERT_VAR_DATA(pPrintInfo);
//
// Fill in the variable-length, concatenated strings
// that follow the PRINT_OTHER_INFO structure.
//
wcscpy_s(p, VAREDSIZE/2, szComputerName); // computername
p += lstrlen(p) + 1;
wcscpy_s(p, (VAREDSIZE/2)-wcslen(szComputerName)-1, szUserName); // username
p += lstrlen(p) + 1;
wcscpy_s(p, (VAREDSIZE/2)-wcslen(szComputerName)-wcslen(szUserName)-2,
szQueueName); // printer queuename
p += lstrlen(p) + 1;
wcscpy_s(p, (VAREDSIZE/2)-wcslen(szComputerName)-wcslen(szUserName)-wcslen(szQueueName)-3,
szDestName); // destination or printer name (optional)
p += lstrlen(p) + 1;
wcscpy_s(p, (VAREDSIZE/2)-wcslen(szComputerName)-wcslen(szUserName)-wcslen(szQueueName)
- wcslen(szDestName)-4, szStatus); // status of the print job (optional)
//
// Call the NetAlertRaiseEx function to raise the
// print alert.
//
dwResult = NetAlertRaiseEx(ALERT_PRINT_EVENT, pPrintInfo, VAREDSIZE, TEXT("MYSERVICE"));
//
// Display the results of the function call.
//
if (dwResult != NERR_Success)
{
wprintf(L"NetAlertRaiseEx failed: %d\\n", dwResult);
return -1;
}
else
wprintf(L"Print alert raised successfully.\\n");

//
// Sending a user alert
//
// Assign values to the members of the USER_OTHER_INFO structure.
//
pUserInfo = (PUSER_OTHER_INFO) buff;
ZeroMemory(pUserInfo, VAREDSIZE);
pUserInfo->alrtus_errcode = -1;
pUserInfo->alrtus_numstrings = 1;
//
// Retrieve a pointer to the variable data portion at the
// end of the buffer by calling the ALERT_VAR_DATA macro.
//
p = (LPTSTR) ALERT_VAR_DATA(pUserInfo);
//
// Fill in the variable-length, concatenated strings
// that follow the USER_OTHER_INFO structure.
//
wcscpy_s(p,(VAREDSIZE/2), TEXT("C:\\\\USERLOG.TXT"));
p += lstrlen(p) + 1;
wcscpy_s(p, (VAREDSIZE/2) - wcslen(TEXT("C:\\\\USERLOG.TXT"))-1, szUserName);
//
// Call the NetAlertRaiseEx function to raise the
// user alert.
//
dwResult = NetAlertRaiseEx(ALERT_USER_EVENT, pUserInfo, VAREDSIZE, TEXT("MYSERVICE"));
//
// Display the results of the function call.
//
if (dwResult != NERR_Success)
{
wprintf(L"NetAlertRaiseEx failed: %d\\n", dwResult);
return -1;
}
else
wprintf(L"User alert raised successfully.\\n");
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
NetAlertRaise
ADMIN_OTHER_INFO
ERRLOG_OTHER_INFO
PRINT_OTHER_INFO
USER_OTHER_INFO
ALERT_VAR_DATA
Send comments about this topic to Microsoft
Build date: 8/13/2009
==原始网址==http://msdn.microsoft.com/en-us/library/aa370298(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:27:21