RasDeleteEntryA 函式 (ras.h)

RasDeleteEntry 函式會從電話簿中刪除專案。

語法

DWORD RasDeleteEntryA(
  [in] LPCSTR unnamedParam1,
  [in] LPCSTR unnamedParam2
);

參數

[in] unnamedParam1

Null 終止字串的指標,指定電話簿 (PBK) 檔案的完整路徑和檔名。 如果此參數為 NULL,函式會使用目前的默認電話簿檔案。 默認電話簿檔案是由使用者選取的 [撥號網络] 對話方塊之 [用戶喜好設定] 屬性表中的使用者所選取的檔案。

Windows Me/98/95: 此參數應一律為 NULL。 撥號網路功能會將電話簿專案儲存在登錄中,而不是儲存在電話簿檔案中。

[in] unnamedParam2

Null 終止字串的指標,指定要刪除之現有項目的名稱。

傳回值

如果函式成功,傳回值會 ERROR_SUCCESS

如果函式失敗,則傳回值是下列其中一個錯誤碼,或 來自路由和遠端訪問錯誤碼 或 Winerror.h 的值。

意義
ERROR_ACCESS_DENIED
用戶沒有正確的許可權。 只有系統管理員可以完成這項工作。
ERROR_INVALID_NAME
lpszEntry 中指定的項目名稱不存在。

備註

下列範例程式代碼會刪除變數 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 5

DWORD __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 initialization 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;
}

注意

ras.h 標頭會將 RasDeleteEntry 定義為別名,根據 UNICODE 預處理器常數的定義,自動選取此函式的 ANSI 或 Unicode 版本。 混合使用編碼中性別名與非編碼中性的程序代碼,可能會導致編譯或運行時間錯誤不符。 如需詳細資訊,請參閱 函式原型的慣例

規格需求

需求
最低支援的用戶端 Windows 2000 Professional [僅限傳統型應用程式]
最低支援的伺服器 Windows 2000 Server [僅限桌面應用程式]
目標平台 Windows
標頭 ras.h
程式庫 Rasapi32.lib
Dll Rasapi32.dll

另請參閱

RasCreatePhonebookEntry

RasEnumEntries

遠端訪問服務 (RAS) 概觀

遠端存取服務函式