RasDeleteEntry

来源:互联网 发布:微信网络诈骗投诉电话 编辑:程序博客网 时间:2024/06/15 06:40
DWORD RasDeleteEntry(  _In_ LPCTSTR lpszPhonebook,  _In_ LPCTSTR lpszEntry);

说明

该函数用于在电话簿中删除条目。

参数

lpszPhonebook[in]

指向一个包含完整路径的电话簿文件(PBK)。如果参数为空,则该函数使用默认的电话簿文件。默认的电话簿文件由用户在拨号网络对话框的[user preferences]属性窗口中选择。

lpszEntry[in]

指向一个要删除的电话簿条目。

返回值

该函数成功时返回ERROR_SUCCESS,并且通过参数lphRasConn 返回连接句柄。失败时返回下列错误码之一,或者来自Routing and Remote Access Error Codes 和 winerror.h中定义的值。
值 含义 ERROR_ACCESS_DENIED 权限不足,只有管理员才能执行此操作。 ERROR_INVALID_NAME lpszEntry指向的电话簿条目无效。

注意事项

以下代码演示如何删除一个电话簿条目。
#include <stdio.h>#include <windows.h>#include "ras.h"#include "strsafe.h"#define PHONE_NUMBER_LENGTH 7#define DEVICE_NAME_LENGTH 5#define DEVICE_TYPE_LENGTH 5DWORD __cdecl wmain(){    DWORD dwRet = ERROR_SUCCESS;    LPTSTR lpszEntry = L"RASEntryName";    LPTSTR lpszphonenumber = L"5555555";    LPTSTR lpszdevicename = L"Modem";    LPTSTR lpszdevicetype = RASDT_Modem;    // Allocate heap memory for the RASENTRY structure    LPRASENTRY lpentry = (LPRASENTRY)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RASENTRY));    if (lpentry == NULL){        printf("HeapAlloc failed");        return 0;       }    // The RASENTRY->dwSize member has to be initialized or the RRAS APIs will fail below.    lpentry->dwSize = sizeof(RASENTRY);    lpentry->dwFramingProtocol = RASFP_Ppp;    lpentry->dwfOptions = 0;    lpentry->dwType = RASET_Phone;    dwRet |= StringCchCopyN(lpentry->szLocalPhoneNumber, RAS_MaxPhoneNumber, lpszphonenumber, PHONE_NUMBER_LENGTH);    dwRet |= StringCchCopyN(lpentry->szDeviceName, RAS_MaxDeviceName, lpszdevicename, DEVICE_NAME_LENGTH);    dwRet |= StringCchCopyN(lpentry->szDeviceType, RAS_MaxDeviceType, lpszdevicetype, DEVICE_TYPE_LENGTH);    if (dwRet != ERROR_SUCCESS){        wprintf(L"RASENTRY structure initilization failed");        HeapFree(GetProcessHeap(), 0, lpentry);        return 0;    }    // Validate the new entry's name    dwRet = RasValidateEntryName(NULL, lpszEntry);    if (dwRet != ERROR_SUCCESS){        wprintf(L"RasValidateEntryName failed: Error = %d\n", dwRet);        HeapFree(GetProcessHeap(), 0, lpentry);        return 0;    }    // Create and set the new entry's properties    dwRet = RasSetEntryProperties(NULL, lpszEntry, lpentry, lpentry->dwSize, NULL, 0);    if (dwRet != ERROR_SUCCESS){        wprintf(L"RasSetEntryProperties failed: Error = %d\n", dwRet);        HeapFree(GetProcessHeap(), 0, lpentry);        return 0;    }    // Clean up: delete the new entry    dwRet = RasDeleteEntry(NULL, lpszEntry);    if (dwRet != ERROR_SUCCESS){        wprintf(L"RasDeleteEntry failed: Error = %d\n", dwRet);    }    HeapFree(GetProcessHeap(), 0, lpentry);    return 0;}

系统支持

客户端最小支持 Windows 2000专业版 服务端最小支持 Windows 2000 Server Header Ras.h Library Rasapi32.lib DLL Rasapi32.dll Unicode和ANSI名称 RasDeleteEntryW (Unicode)和RasDeleteEntryA (ANSI)
0 0