断开拨号连接(50分)

  • 主题发起人 主题发起人 tsedlinux
  • 开始时间 开始时间
T

tsedlinux

Unregistered / Unconfirmed
GUEST, unregistred user!
有什么办法能断开WINDOWS的拨号连接?
 
拔电话线,呵呵呵
 
没人知道吗?

很难吗?
 
是不是真的很难?

拔电话线还不如关机呢

更省电
 
uses wininet.pas
setinternetoption
 
先用RAsEnumConnection列出当前的连接,得到连接句并,再用HangUp挂断
这是我想的,没试过,你可以试一下
 
没有人知道吗?
 
procedure TForm1.Button1Click(Sender: TObject);
var
RasConns: array[1..20] of TRasConn;
i, dwBufSize, dwConnections,FlastError: DWord;
RasConn: HRasConn;
begin
RasConns[1].dwSize := SizeOf(TRasConn);
dwBufSize := SizeOf(RasConns);
FLastError := RasEnumConnections(@RasConns, dwBufSize, dwConnections);
if (FLastError = 0) or (FLastError = ERROR_BUFFER_TOO_SMALL) then
for i := 1 to dwConnections do
if (i < 21) then//and (StrIComp(RasConns.szEntryName, PChar(FEntryName)) = 0) then
begin
RasConn := RasConns.hRasConn;
listbox1.Items.Add(rasconns[1].szEntryName);
FLastError := RasHangUp(RasConn);
end;
end;
 
TO XIANGHB
可否把USE,CONST,TYPE,PUBLIC,PRIVATE段的代码都贴出来?
 
不好意思,你还得uses ras.pad

unit Ras;

{nothing} // for Windows 95, Windows NT SUR (default)
{.$DEFINE WINVER41} // for Windows NT SUR enhancements
{$ALIGN ON}

interface

uses Windows, Messages, SysUtils;

const
DNLEN = 15; // Maximum domain name length
UNLEN = 256; // Maximum user name length
PWLEN = 256; // Maximum password length
NETBIOS_NAME_LEN = 16; // NetBIOS net name (bytes)

RAS_MaxDeviceType = 16;
RAS_MaxPhoneNumber = 128;
RAS_MaxIpAddress = 15;
RAS_MaxIpxAddress = 21;

RAS_MaxEntryName = 256;
RAS_MaxDeviceName = 128;
RAS_MaxCallbackNumber = RAS_MaxPhoneNumber;

RAS_MaxAreaCode = 10;
RAS_MaxPadType = 32;
RAS_MaxX25Address = 200;
RAS_MaxFacilities = 200;
RAS_MaxUserData = 200;

const
// Enumerates intermediate states to a connection. (See RasDial)
RASCS_Paused = $1000;
RASCS_Done = $2000;

RASCS_OpenPort = 0;
RASCS_PortOpened = 1;
RASCS_ConnectDevice = 2;
RASCS_DeviceConnected = 3;
RASCS_AllDevicesConnected = 4;
RASCS_Authenticate = 5;
RASCS_AuthNotify = 6;
RASCS_AuthRetry = 7;
RASCS_AuthCallback = 8;
RASCS_AuthChangePassword = 9;
RASCS_AuthProject = 10;
RASCS_AuthLinkSpeed = 11;
RASCS_AuthAck = 12;
RASCS_ReAuthenticate = 13;
RASCS_Authenticated = 14;
RASCS_PrepareForCallback = 15;
RASCS_WaitForModemReset = 16;
RASCS_WaitForCallback = 17;
RASCS_Projected = 18;
RASCS_StartAuthentication = 19;
RASCS_CallbackComplete = 20;
RASCS_LogonNetwork = 21;

RASCS_Interactive = RASCS_PAUSED;
RASCS_RetryAuthentication = RASCS_PAUSED + 1;
RASCS_CallbackSetByCaller = RASCS_PAUSED + 2;
RASCS_PasswordExpired = RASCS_PAUSED + 3;

RASCS_Connected = RASCS_DONE;
RASCS_Disconnected = RASCS_DONE + 1;

const
ERROR_ALREADY_EXISTS = 183;

const
RASBase = 600;
Success = 0;
{ Error Codes }
PENDING = (RASBase+0); //An operation is pending.
ERROR_INVALID_PORT_HANDLE = (RASBase+1); //The port handle is invalid.
ERROR_PORT_ALREADY_OPEN = (RASBase+2); //The port is already open.
ERROR_BUFFER_TOO_SMALL = (RASBase+3); //Caller's buffer is too small.
ERROR_WRONG_INFO_SPECIFIED = (RASBase+4); //Wrong information specified.
ERROR_CANNOT_SET_PORT_INFO = (RASBase+5); //Cannot set port information.
ERROR_PORT_NOT_ConnECTED = (RASBase+6); //The port is not connected.
ERROR_EVENT_INVALID = (RASBase+7); //The event is invalid.
ERROR_DEVICE_DOES_NOT_EXIST = (RASBase+8); //The device does not exist.
ERROR_DEVICETYPE_DOES_NOT_EXIST = (RASBase+9); //The device type does not exist.
ERROR_INVALID_BUFFER = (RASBase+10); //The buffer is invalid.
ERROR_ROUTE_NOT_AVAILABLE = (RASBase+11); //The route is not available.
ERROR_ROUTE_NOT_ALLOCATED = (RASBase+12); //The route is not allocated.
ERROR_INVALID_COMPRESSION_SPECIFIED = (RASBase+13); //Invalid compression specified.
ERROR_OUT_OF_BUFFERS = (RASBase+14); //Out of buffers.
ERROR_PORT_NOT_FOUND = (RASBase+15); //The port was not found.
ERROR_ASYNC_REQUEST_PENDING = (RASBase+16); //An asynchronous request is pending.
ERROR_ALREADY_DISConnECTING = (RASBase+17); //The port or device is already disconnecting.
ERROR_PORT_NOT_OPEN = (RASBase+18); //The port is not open.
ERROR_PORT_DISConnECTED = (RASBase+19); //The port is disconnected.
ERROR_NO_ENDPOINTS = (RASBase+20); //There are no endpoints.
ERROR_CANNOT_OPEN_PHONEBOOK = (RASBase+21); //Cannot open the phone book file.
ERROR_CANNOT_LOAD_PHONEBOOK = (RASBase+22); //Cannot load the phone book file.
ERROR_CANNOT_FIND_PHONEBOOK_ENTRY = (RASBase+23); //Cannot find the phone book entry.
ERROR_CANNOT_WRITE_PHONEBOOK = (RASBase+24); //Cannot write the phone book file.
ERROR_CORRUPT_PHONEBOOK = (RASBase+25); //Invalid information found in the phone book file.
ERROR_CANNOT_LOAD_STRING = (RASBase+26); //Cannot load a string.
ERROR_KEY_NOT_FOUND = (RASBase+27); //Cannot find key.
ERROR_DISConnECTION = (RASBase+28); //The port was disconnected.
ERROR_REMOTE_DISCONNECTION = (RASBase+29); //The port was disconnected by the remote machine.
ERROR_HARDWARE_FAILURE = (RASBase+30); //The port was disconnected due to hardware failure.
ERROR_USER_DISCONNECTION = (RASBase+31); //The port was disconnected by the user.
ERROR_INVALID_SIZE = (RASBase+32); //The structure size is incorrect.
ERROR_PORT_NOT_AVAILABLE = (RASBase+33); //The port is already in use or is not configured for Remote Access dial out.
ERROR_CANNOT_PROJECT_CLIENT = (RASBase+34); //Cannot register your computer on on the remote network.
ERROR_UNKNOWN = (RASBase+35); //Unknown error.
ERROR_WRONG_DEVICE_ATTACHED = (RASBase+36); //The wrong device is attached to the port.
ERROR_BAD_STRING = (RASBase+37); //The string could not be converted.
ERROR_REQUEST_TIMEOUT = (RASBase+38); //The request has timed out.
ERROR_CANNOT_GET_LANA = (RASBase+39); //No asynchronous net available.
ERROR_NETBIOS_ERROR = (RASBase+40); //A NetBIOS error has occurred.
ERROR_SERVER_OUT_OF_RESOURCES = (RASBase+41); //The server cannot allocate NetBIOS resources needed to support the client.
ERROR_NAME_EXISTS_ON_NET = (RASBase+42); //One of your NetBIOS names is already registered on the remote network.
ERROR_SERVER_GENERAL_NET_FAILURE = (RASBase+43); //A network adapter at the server failed.
WARNING_MSG_ALIAS_NOT_ADDED = (RASBase+44); //You will not receive network message popups.
ERROR_AUTH_INTERNAL = (RASBase+45); //Internal authentication error.
ERROR_RESTRICTED_LOGON_HOURS = (RASBase+46); //The account is not permitted to logon at this time of day.
ERROR_ACCT_DISABLED = (RASBase+47); //The account is disabled.
ERROR_PASSWD_EXPIRED = (RASBase+48); //The password has expired.
ERROR_NO_DIALIN_PERMISSION = (RASBase+49); //The account does not have Remote Access permission.
ERROR_SERVER_NOT_RESPONDING = (RASBase+50); //The Remote Access server is not responding.
ERROR_FROM_DEVICE = (RASBase+51); //Your modem (or other connecting device) has reported an error.
ERROR_UNRECOGNIZED_RESPONSE = (RASBase+52); //Unrecognized response from the device.
ERROR_MACRO_NOT_FOUND = (RASBase+53); //A macro required by the device was not found in the device .INF file section.
ERROR_MACRO_NOT_DEFINED = (RASBase+54); //A command or response in the device .INF file section refers to an undefined macro.
ERROR_MESSAGE_MACRO_NOT_FOUND = (RASBase+55); //The <message> macro was not found in the device .INF file secion.
ERROR_DEFAULTOFF_MACRO_NOT_FOUND = (RASBase+56); //The <defaultoff> macro in the device .INF file section contains an undefined macro.
ERROR_FILE_COULD_NOT_BE_OPENED = (RASBase+57); //The device .INF file could not be opened.
ERROR_DEVICENAME_TOO_LONG = (RASBase+58); //The device name in the device .INF or media .INI file is too long.
ERROR_DEVICENAME_NOT_FOUND = (RASBase+59); //The media .INI file refers to an unknown device name.
ERROR_NO_RESPONSES = (RASBase+60); //The device .INF file contains no responses for the command.
ERROR_NO_COMMAND_FOUND = (RASBase+61); //The device .INF file is missing a command.
ERROR_WRONG_KEY_SPECIFIED = (RASBase+62); //Attempted to set a macro not listed in device .INF file section.
ERROR_UNKNOWN_DEVICE_TYPE = (RASBase+63); //The media .INI file refers to an unknown device type.
ERROR_ALLOCATING_MEMORY = (RASBase+64); //Cannot allocate memory.
ERROR_PORT_NOT_CONFIGURED = (RASBase+65); //The port is not configured for Remote Access.
ERROR_DEVICE_NOT_READY = (RASBase+66); //Your modem (or other connecting device) is not functioning.
ERROR_READING_INI_FILE = (RASBase+67); //Cannot read the media .INI file.
ERROR_NO_ConnECTION = (RASBase+68); //The connection dropped.
ERROR_BAD_USAGE_IN_INI_FILE = (RASBase+69); //The usage parameter in the media .INI file is invalid.
ERROR_READING_SECTIONNAME = (RASBase+70); //Cannot read the section name from the media .INI file.
ERROR_READING_DEVICETYPE = (RASBase+71); //Cannot read the device type from the media .INI file.
ERROR_READING_DEVICENAME = (RASBase+72); //Cannot read the device name from the media .INI file.
ERROR_READING_USAGE = (RASBase+73); //Cannot read the usage from the media .INI file.
ERROR_READING_MAXConnECTBPS = (RASBase+74); //Cannot read the maximum connection BPS rate from the media .INI file.
ERROR_READING_MAXCARRIERBPS = (RASBase+75); //Cannot read the maximum carrier BPS rate from the media .INI file.
ERROR_LINE_BUSY = (RASBase+76); //The line is busy.
ERROR_VOICE_ANSWER = (RASBase+77); //A person answered instead of a modem.
ERROR_NO_ANSWER = (RASBase+78); //There is no answer.
ERROR_NO_CARRIER = (RASBase+79); //Cannot detect carrier.
ERROR_NO_DIALTONE = (RASBase+80); //There is no dial tone.
ERROR_IN_COMMAND = (RASBase+81); //General error reported by device.
ERROR_WRITING_SECTIONNAME = (RASBase+82); //91: Access denied because username and/or password is invalid on the domain.
ERROR_WRITING_DEVICETYPE = (RASBase+83); //Hardware failure in port or attached device.
ERROR_WRITING_DEVICENAME = (RASBase+84);
ERROR_WRITING_MAXConnECTBPS = (RASBase+85);
ERROR_WRITING_MAXCARRIERBPS = (RASBase+86);
ERROR_WRITING_USAGE = (RASBase+87);
ERROR_WRITING_DEFAULTOFF = (RASBase+88);
ERROR_READING_DEFAULTOFF = (RASBase+89);
ERROR_EMPTY_INI_FILE = (RASBase+90);
ERROR_AUTHENTICATION_FAILURE = (RASBase+91);
ERROR_PORT_OR_DEVICE = (RASBase+92);
ERROR_NOT_BINARY_MACRO = (RASBase+93);
ERROR_DCB_NOT_FOUND = (RASBase+94);
ERROR_STATE_MACHINES_NOT_STARTED = (RASBase+95);
ERROR_STATE_MACHINES_ALREADY_STARTED = (RASBase+96);
ERROR_PARTIAL_RESPONSE_LOOPING = (RASBase+97);
ERROR_UNKNOWN_RESPONSE_KEY = (RASBase+98); //A response keyname in the device .INF file is not in the expected format.
ERROR_RECV_BUF_FULL = (RASBase+99); //The device response caused buffer overflow.
ERROR_CMD_TOO_LONG = (RASBase+100); //The expanded command in the device .INF file is too long.
ERROR_UNSUPPORTED_BPS = (RASBase+101); //The device moved to a BPS rate not supported by the COM driver.
ERROR_UNEXPECTED_RESPONSE = (RASBase+102); //Device response received when none expected.
ERROR_INTERACTIVE_MODE = (RASBase+103);
ERROR_BAD_CALLBACK_NUMBER = (RASBase+104);
ERROR_INVALID_AUTH_STATE = (RASBase+105);
ERROR_WRITING_INITBPS = (RASBase+106);
ERROR_X25_DIAGNOSTIC = (RASBASE+107); //X.25 diagnostic indication.
ERROR_ACCT_EXPIRED = (RASBASE+108); //The account has expired.
ERROR_CHANGING_PASSWORD = (RASBASE+109); //Error changing password on domain. The password may be too short or may match a previously used password.
ERROR_OVERRUN = (RASBASE+110); //Serial overrun errors were detected while communicating with your modem.
ERROR_RASMAN_CANNOT_INITIALIZE = (RASBASE+111); //RasMan initialization failure. Check the event log.
ERROR_BIPLEX_PORT_NOT_AVAILABLE = (RASBASE+112); //Biplex port initializing. Wait a few seconds and redial.
ERROR_NO_ACTIVE_ISDN_LINES = (RASBASE+113); //No active ISDN lines are available.
ERROR_NO_ISDN_CHANNELS_AVAILABLE = (RASBASE+114); //No ISDN channels are available to make the call.
ERROR_TOO_MANY_LINE_ERRORS = (RASBASE+115); //Too many errors occured because of poor phone line quality.
ERROR_IP_CONFIGURATION = (RASBASE+116);
ERROR_NO_IP_ADDRESSES = (RASBASE+117); //No IP addresses are available in the static pool of Remote Access IP addresses.
ERROR_PPP_TIMEOUT = (RASBASE+118); //Timed out waiting for a valid response from the remote PPP peer.
ERROR_PPP_REMOTE_TERMINATED = (RASBASE+119); //PPP terminated by remote machine.
ERROR_PPP_NO_PROTOCOLS_CONFIGURED = (RASBASE+120); //No PPP control protocols configured.
ERROR_PPP_NO_RESPONSE = (RASBASE+121); //Remote PPP peer is not responding.
ERROR_PPP_INVALID_PACKET = (RASBASE+122); //The PPP packet is invalid.
ERROR_PHONE_NUMBER_TOO_LONG = (RASBASE+123); //The phone number including prefix and suffix is too long.
ERROR_IPXCP_NO_DIALOUT_CONFIGURED = (RASBASE+124); //The IPX protocol cannot dial-out on the port because the machine is an IPX router.
ERROR_IPXCP_NO_DIALIN_CONFIGURED = (RASBASE+125); //The IPX protocol cannot dial-in on the port because the IPX router is not installed.
ERROR_IPXCP_DIALOUT_ALREADY_ACTIVE = (RASBASE+126); //The IPX protocol cannot be used for dial-out on more than one port at a time.
ERROR_ACCESSING_TCPCFGDLL = (RASBASE+127); //Cannot access TCPCFG.DLL.
ERROR_NO_IP_RAS_ADAPTER = (RASBASE+128); //Cannot find an IP adapter bound to Remote Access.
ERROR_SLIP_REQUIRES_IP = (RASBASE+129); //SLIP cannot be used unless the IP protocol is installed.
ERROR_PROJECTION_NOT_COMPLETE = (RASBASE+130); //Computer registration is not complete.
ERROR_PROTOCOL_NOT_CONFIGURED = (RASBASE+131); //The protocol is not configured.
ERROR_PPP_NOT_CONVERGING = (RASBASE+132); //The PPP negotiation is not converging.
ERROR_PPP_CP_REJECTED = (RASBASE+133); //The PPP control protocol for this network protocol is not available on the server.
ERROR_PPP_LCP_TERMINATED = (RASBASE+134); //The PPP link control protocol terminated.
ERROR_PPP_REQUIRED_ADDRESS_REJECTED = (RASBASE+135); //The requested address was rejected by the server.
ERROR_PPP_NCP_TERMINATED = (RASBASE+136); //The remote computer terminated the control protocol.
ERROR_PPP_LOOPBACK_DETECTED = (RASBASE+137); //Loopback detected.
ERROR_PPP_NO_ADDRESS_ASSIGNED = (RASBASE+138); //The server did not assign an address.
ERROR_CANNOT_USE_LOGON_CREDENTIALS = (RASBASE+139); //The authentication protocol required by the remote server cannot use the Windows NT encrypted password. Redial, entering the password explicitly.
ERROR_TAPI_CONFIGURATION = (RASBASE+140); //Invalid TAPI configuration.
ERROR_NO_LOCAL_ENCRYPTION = (RASBASE+141); //The local computer does not support encryption.
ERROR_NO_REMOTE_ENCRYPTION = (RASBASE+142); //The remote server does not support encryption.
ERROR_REMOTE_REQUIRES_ENCRYPTION = (RASBASE+143); //The remote server requires encryption.
ERROR_IPXCP_NET_NUMBER_CONFLICT = (RASBASE+144); //Cannot use the IPX network number assigned by remote server. Check the event log.
ERROR_INVALID_SMM = (RASBASE+145);
ERROR_SMM_UNINITIALIZED = (RASBASE+146);
ERROR_NO_MAC_FOR_PORT = (RASBASE+147);
ERROR_SMM_TIMEOUT = (RASBASE+148);
ERROR_BAD_PHONE_NUMBER = (RASBASE+149);
ERROR_WRONG_MODULE = (RASBASE+150);
ERROR_INVALID_CALLBACK_NUMBER = (RASBASE+151); //Invalid callback number. Only the characters 0 to 9, T, P, W, (, ), -, @, and space are allowed in the number.
ERROR_SCRIPT_SYNTAX = (RASBASE+152); //A syntax error was encountered while processing a script.
RASBASEEND = (RASBASE+152);

type
PHRasConn = ^HRasConn;
HRasConn = Longint;
PRasConnState = ^TRasConnState;
TRasConnState = Integer;

//Identifies an active RAS connection. (See RasEnumConnections)
PRasConn = ^TRasConn;
TRasConn = record
dwSize: Longint;
hRasConn: HRasConn;
szEntryName: array[0..RAS_MaxEntryName] of AnsiChar;
szDeviceType: array[0..RAS_MaxDeviceType] of AnsiChar;
szDeviceName: array[0..RAS_MaxDeviceName] of AnsiChar;
{$IFDEF WINVER41}
szPhonebook: array[0..MAX_PATH - 1] of AnsiChar;
dwSubEntry: Longint;
{$ENDIF}
end;

//Describes the status of a RAS connection. (See RasConnectionStatus)
PRasConnStatus = ^TRasConnStatus;
TRasConnStatus = record
dwSize: Longint;
rasconnstate: TRasConnState;
dwError: LongInt;
szDeviceType: array[0..RAS_MaxDeviceType] of AnsiChar;
szDeviceName: array[0..RAS_MaxDeviceName] of AnsiChar;
{$IFDEF WINVER41}
swPhoneNumber: array[0..RAS_MaxPhoneNumber] of AnsiChar;
{$ENDIF}
end;

// Describes connection establishment parameters. (See RasDial)
PRasDialParams = ^TRasDialParams;
TRasDialParams = record
dwSize: LongInt;
szEntryName: array[0..RAS_MaxEntryName] of AnsiChar;
szPhoneNumber: array[0..RAS_MaxPhoneNumber] of AnsiChar;
szCallbackNumber: array[0..RAS_MaxCallbackNumber] of AnsiChar;
szUserName: array[0..UNLEN] of AnsiChar;
szPassword: array[0..PWLEN] of AnsiChar;
szDomain: array[0..DNLEN] of AnsiChar;
{$IFDEF WINVER41}
dwSubEntry: Longint;
dwCallbackId: Longint;
{$ENDIF}
end;

//Describes extended connection establishment options. (See RasDial)
LPRasDialExtensions = ^TRasDialExtensions;
TRasDialExtensions = record
dwSize: LongInt;
dwfOptions: LongInt;
hwndParent: HWND;
reserved: LongInt;
end;

const
// 'dwfOptions' bit flags.
RDEOPT_UsePrefixSuffix = $00000001;
RDEOPT_PausedStates = $00000002;
RDEOPT_IgnoreModemSpeaker = $00000004;
RDEOPT_SetModemSpeaker = $00000008;
RDEOPT_IgnoreSoftwareCompression = $00000010;
RDEOPT_SetSoftwareCompression = $00000020;
RDEOPT_DisableConnectedUI = $00000040;
RDEOPT_DisableReconnectUI = $00000080;
RDEOPT_DisableReconnect = $00000100;
RDEOPT_NoUser = $00000200;
RDEOPT_PauseOnScript = $00000400;

type
//Describes an enumerated RAS phone book entry name. (See RasEntryEnum)
PRasEntryName = ^TRasEntryName;
TRasEntryName = record
dwSize: Longint;
szEntryName: array[0..RAS_MaxEntryName] of AnsiChar;
end;

//Protocol code to projection data structure mapping.
PRasProjection = ^TRasProjection;
TRasProjection = Integer;

const
RASP_Amb = $10000;
RASP_PppNbf = $803F;
RASP_PppIpx = $802B;
RASP_PppIp = $8021;
RASP_PppLcp = $C021;
RASP_Slip = $20000;

type
//Describes the result of a RAS AMB (Authentication Message Block)
// projection. This protocol is used with NT 3.1 and OS/2 1.3 downlevel
// RAS servers.
PRasAmbA = ^TRasAmbA;
TRasAmbA = record
dwSize: Longint;
dwError: Longint;
szNetBiosError: array[0..NETBIOS_NAME_LEN] of AnsiChar;
bLana: Byte;
end;

//Describes the result of a PPP NBF (NetBEUI) projection.
PRasPppNbf = ^TRasPppNbf;
TRasPppNbf = record
dwSize: Longint;
dwError: Longint;
dwNetBiosError: Longint;
szNetBiosError: array[0..NETBIOS_NAME_LEN] of AnsiChar;
szWorkstationName: array[0..NETBIOS_NAME_LEN] of AnsiChar;
bLana: Byte;
end;

// Describes the results of a PPP IPX (Internetwork Packet Exchange) projection.
PRasPppIpx = ^TRasPppIpx;
TRasPppIpx = record
dwSize: Longint;
dwError: Longint;
szIpxAddress: array[0..RAS_MaxIpxAddress] of AnsiChar;
end;

//Describes the results of a PPP IP (Internet) projection.
PRasPppIp = ^TRasPppIp;
TRasPppIp = record
dwSize: Longint;
dwError: Longint;
szIpAddress: array[0..RAS_MaxIpAddress] of AnsiChar;
{$IFNDEF WINNT35COMPATIBLE}
{* This field was added between Windows NT 3.51 beta and Windows NT 3.51
** final, and between Windows 95 M8 beta and Windows 95 final. If you do
** not require the server address and wish to retrieve PPP IP information
** from Windows NT 3.5 or early Windows NT 3.51 betas, or on early Windows
** 95 betas, define WINNT35COMPATIBLE.
**
** The server IP address is not provided by all PPP implementations,
** though Windows NT server's do provide it.
*}
szServerIpAddress: array[0..RAS_MaxIpAddress] of AnsiChar;
{$ENDIF}
end;

//Describes the results of a PPP LCP/multi-link negotiation.
LpRasPppLcp = ^TRasPppLcp;
TRasPppLcp = record
dwSize: Longint;
fBundled: LongBool;
end;

//Describes the results of a SLIP (Serial Line IP) projection.
PRasSlip = ^TRasSlip;
TRasSlip = record
dwSize: Longint;
dwError: Longint;
szIpAddress: array[0..RAS_MaxIpAddress] of AnsiChar;
end;

const
{* If using RasDial message notifications, get the notification message code
** by passing this string to the RegisterWindowMessageA() API.
** WM_RASDIALEVENT is used only if a unique message cannot be registered.
*}
RasDialEvent = 'RasDialEvent';
WM_RasDialEvent = $CCCD;

{* Prototypes for caller's RasDial callback handler. Arguments are the
** message ID (currently always WM_RASDIALEVENT), the current RASCONNSTATE and
** the error that has occurred (or 0 if none). Extended arguments are the
** handle of the RAS connection and an extended error code.
**
** For RASDIALFUNC2, subsequent callback notifications for all
** subentries can be cancelled by returning FALSE.
*}
{
typedef VOID (WINAPI *RASDIALFUNC)( UINT, RASCONNSTATE, DWORD );
typedef VOID (WINAPI *RASDIALFUNC1)( HRasConn, UINT, RASCONNSTATE, DWORD, DWORD );
typedef DWORD (WINAPI *RASDIALFUNC2)( DWORD, DWORD, HRasConn, UINT, RASCONNSTATE, DWORD, DWORD );

For Delphi: Just define the callback as:

procedure RASCallback(msg: Integer; state: TRasConnState;
dwError: Longint); stdcall;

procedure RASCallback1(hConn: HRasConn; msg: Integer;
state: TRasConnState; dwError: Longint; dwEexterror: Longint); stdcall;

procedure RASCallback2(dwCallbackId, dwSubEntry: Longint; hConn: HRasConn;
msg: Integer; state: TRasConnState; dwError: Longint;
dwEexterror: Longint); stdcall;
}

type
// Information describing a RAS-capable device.
PRasDevInfo = ^TRasDevInfo;
TRasDevInfo = record
dwSize: Longint;
szDeviceType: array[0..RAS_MaxDeviceType] of AnsiChar;
szDeviceName: array[0..RAS_MaxDeviceName] of AnsiChar;
end;

//RAS Country Information (currently retreieved from TAPI).
PRasCtryInfo = ^TRasCtryInfo;
TRasCtryInfo = record
dwSize,
dwCountryID,
dwNextCountryID,
dwCountryCode,
dwCountryNameOffset: Longint;
end;

//A RAS IP Address.
PRasIPAddr = ^TRasIPAddr;
TRasIPAddr = record
a, b, c, d: Byte;
end;

//A RAS phonebook entry.
PRasEntry = ^TRasEntry;
TRasEntry = record
dwSize,
dwfOptions,
//
// Location/phone number.
//
dwCountryID,
dwCountryCode: Longint;
szAreaCode: array[0.. RAS_MaxAreaCode] of AnsiChar;
szLocalPhoneNumber: array[0..RAS_MaxPhoneNumber] of AnsiChar;
dwAlternatesOffset: Longint;
//
// PPP/Ip
//
ipaddr,
ipaddrDns,
ipaddrDnsAlt,
ipaddrWins,
ipaddrWinsAlt: TRasIPAddr;
//
// Framing
//
dwFrameSize,
dwfNetProtocols,
dwFramingProtocol: Longint;
//
// Scripting
//
szScript: array[0..MAX_PATH - 1] of AnsiChar;
//
// AutoDial
//
szAutodialDll: array [0..MAX_PATH - 1] of AnsiChar;
szAutodialFunc: array [0..MAX_PATH - 1] of AnsiChar;
//
// Device
//
szDeviceType: array [0..RAS_MaxDeviceType] of AnsiChar;
szDeviceName: array [0..RAS_MaxDeviceName] of AnsiChar;
//
// X.25
//
szX25PadType: array [0..RAS_MaxPadType] of AnsiChar;
szX25Address: array [0..RAS_MaxX25Address] of AnsiChar;
szX25Facilities: array [0..RAS_MaxFacilities] of AnsiChar;
szX25UserData: array [0..RAS_MaxUserData] of AnsiChar;
dwChannels: Longint;
//
// Reserved
//
dwReserved1,
dwReserved2: Longint;
{$IFDEF WINVER41}
//
// Multilink
//
dwSubEntries,
dwDialMode,
dwDialExtraPercent,
dwDialExtraSampleSeconds,
dwHangUpExtraPercent,
dwHangUpExtraSampleSeconds: Longint;
//
// Idle timeout
//
dwIdleDisconnectSeconds: Longint;
{$ENDIF}
end;

const
//TRasEntry 'dwfOptions' bit flags.
RASEO_UseCountryAndAreaCodes = $00000001;
RASEO_SpecificIpAddr = $00000002;
RASEO_SpecificNameServers = $00000004;
RASEO_IpHeaderCompression = $00000008;
RASEO_RemoteDefaultGateway = $00000010;
RASEO_DisableLcpExtensions = $00000020;
RASEO_TerminalBeforeDial = $00000040;
RASEO_TerminalAfterDial = $00000080;
RASEO_ModemLights = $00000100;
RASEO_SwCompression = $00000200;
RASEO_RequireEncryptedPw = $00000400;
RASEO_RequireMsEncryptedPw = $00000800;
RASEO_RequireDataEncryption = $00001000;
RASEO_NetworkLogon = $00002000;
RASEO_UseLogonCredentials = $00004000;
RASEO_PromoteAlternates = $00008000;
{$IFDEF WINVER41}
RASEO_SecureLocalFiles = $00010000;
{$ENDIF}

//TRasEntry 'dwfNetProtocols' bit flags. (session negotiated protocols)
RASNP_Netbeui = $00000001; // Negotiate NetBEUI
RASNP_Ipx = $00000002; // Negotiate IPX
RASNP_Ip = $00000004; // Negotiate TCP/IP

//TRasEntry 'dwFramingProtocols' (framing protocols used by the server)
RASFP_Ppp = $00000001; // Point-to-Point Protocol (PPP)
RASFP_Slip = $00000002; // Serial Line Internet Protocol (SLIP)
RASFP_Ras = $00000004; // Microsoft proprietary protocol

//TRasEntry 'szDeviceType' strings
RASDT_Modem = 'modem'; // Modem
RASDT_Isdn = 'isdn'; // ISDN
RASDT_X25 = 'x25'; // X.25


{$IFDEF WINVER41}
//Flags for RasConnectionNotification().
RASCN_Connection = $00000001;
RASCN_Disconnection = $00000002;
RASCN_BandwidthAdded = $00000004;
RASCN_BandwidthRemoved = $00000008;

//TRasEntry 'dwDialMode' values.
RASEDM_DialAll = 1;
RASEDM_DialAsNeeded = 2;

//TRasEntry 'dwIdleDisconnectSeconds' constants.
RASIDS_Disabled = $ffffffff;
RASIDS_UseGlobalValue = 0;

type
// AutoDial DLL function parameter block.
PRasADParams = ^TRasADParams;
TRasADParams = record
dwSize: Longint;
hwndOwner: THandle;
dwFlags: Longint;
xDlg,
yDlg: Longint;
end;

const
//AutoDial DLL function parameter block 'dwFlags.'
RASADFLG_PositionDlg = $00000001;

// Prototype AutoDial DLL function.
{
typedef BOOL (WINAPI *RASADFUNCA)( LPSTR, LPSTR, PRasADParams, LPDWORD );
typedef BOOL (WINAPI *RASADFUNCW)( LPWSTR, LPWSTR, PRasADParams, LPDWORD );

For Delphi:

function RasAdFuncA(lpszPhonebook, lpszEntry: PAnsiChar;
var lpAutoDialParams: TRasADParams;
var lpdwRetCode: Longint): Boolean; stdcall;

function RasAdFuncW(lpszPhonebook, lpszEntry: PWideChar;
var lpAutoDialParams: TRasADParams;
var lpdwRetCode: Longint): Boolean; stdcall;
}

type
//A RAS phone book multilinked sub-entry.
PRasSubEntry = ^TRasSubEntry;
TRasSubEntry = record
dwSize,
dwfFlags: Longint;
//
// Device
//
szDeviceType: array[0..RAS_MaxDeviceType] of AnsiChar;
szDeviceName: array[0..RAS_MaxDeviceName] of AnsiChar;
//
// Phone numbers
//
szLocalPhoneNumber: array[0..RAS_MaxPhoneNumber] of AnsiChar;
dwAlternateOffset: Longint;
end;

//Ras(Get,Set)Credentials structure. These calls
// supercede Ras(Get,Set)EntryDialParams.
PRasCredentials = ^TRasCredentials;
TRasCredentials = record
dwSize,
dwMask: Longint;
szUserName: array[0..UNLEN] of AnsiChar;
zPassword: array[0..PWLEN ] of AnsiChar;
szDomain: array[0..DNLEN] of AnsiChar;
end;

const
//TRasCredentials 'dwMask' values.
RASCM_UserName = $00000001;
RASCM_Password = $00000002;
RASCM_Domain = $00000004;

type
// AutoDial address properties.
PRasAutoDialEntry = ^TRasAutoDialEntry;
TRasAutoDialEntry = record
dwSize,
dwFlags,
dwDialingLocation: Longint;
szEntry: array[0..RAS_MaxEntryName] of AnsiChar;
end;

const
//AutoDial control parameter values for
// Ras(Get,Set)AutodialParam.
RASADP_DisableConnectionQuery = 0;
RASADP_LoginSessionDisable = 1;
RASADP_SavedAddressesLimit = 2;
RASADP_FailedConnectionTimeout = 3;
RASADP_ConnectionQueryTimeout = 4;
{$ENDIF} // WINVER41


// External RAS API function prototypes.
function RasDial(
lpRasDialExt: LPRasDialExtensions;
lpszPhoneBook: PChar;
var params: TRasDialParams;
dwNotifierType: DWord;
lpNotifier: DWord; //Pointer;
var rasconn: HRasConn
): Longint; stdcall;

function RasEnumConnections(
rasconnArray: PRasConn;
var lpcb: DWord;
var lpcConnections: DWord
): Longint; stdcall;

function RasEnumEntries(
reserved: PChar;
lpszPhoneBook: PChar;
entrynamesArray: PRasEntryName;
var lpcb: DWord; //Longint;
var lpcEntries: DWord //Longint
): Longint; stdcall;

function RasGetConnectStatus(
hConn: HRasConn;
var lpStatus: TRasConnStatus
): Longint; stdcall;

function RasGetErrorString(
errorValue: Integer;
erroString: PChar;
cBufSize: Longint
): Longint; stdcall;

function RasHangUp(
hConn: HRasConn
): Longint; stdcall;

function RasGetProjectionInfo(
hConn: HRasConn;
rasproj: TRasProjection;
lpProjection: Pointer;
var lpcb: Longint
): Longint; stdcall;

function RasCreatePhonebookEntry(
hwndParentWindow: HWND;
lpszPhoneBook: PChar
): Longint; stdcall;

function RasEditPhonebookEntry(
hwndParentWindow: HWND;
lpszPhoneBook: PChar;
lpszEntryName: PChar
): Longint; stdcall;

function RasSetEntryDialParams(
lpszPhoneBook: PChar;
var lpDialParams: TRasDialParams;
fRemovePassword: LongBool
): Longint; stdcall;

function RasGetEntryDialParams(
lpszPhoneBook: PChar;
var lpDialParams: TRasDialParams;
var lpfPassword: LongBool
): Longint; stdcall;

function RasEnumDevices(
lpBuff: PRasDevInfo;
var lpcbSize: Longint;
var lpcDevices: Longint
): Longint; stdcall;

function RasGetCountryInfo(
lpCtryInfo: PRasCtryInfo;
var lpdwSize: Longint
): Longint; stdcall;

function RasGetEntryProperties(
lpszPhonebook,
szEntry: PChar;
lpbEntry: Pointer;
var lpdwEntrySize: Longint;
lpbDeviceInfo: Pointer;
var lpdwDeviceInfoSize: Longint
): Longint; stdcall;

function RasSetEntryProperties(
lpszPhonebook,
szEntry: PChar;
lpbEntry: Pointer;
dwEntrySize: Longint;
lpbDeviceInfo: Pointer;
dwDeviceInfoSize: Longint
): Longint; stdcall;

function RasRenameEntry(
lpszPhonebook,
szEntryOld,
szEntryNew: PChar
): Longint; stdcall;

function RasDeleteEntry(
lpszPhonebook,
szEntry: PChar
): Longint; stdcall;

function RasValidateEntryName(
lpszPhonebook,
szEntry: PChar
): Longint; stdcall;

{$IFDEF WINVER41}
function RasGetSubEntryHandle(
hrasconn: HRasConn;
dwSubEntry: Longint;
var lphrasconn: HRasConn
): Longint; stdcall;

function RasGetCredentials(
lpszPhoneBook,
lpszEntry: PChar;
var lpCredentials: TRasCredentials
): Longint; stdcall;

function RasSetCredentials(
lpszPhoneBook,
lpszEntry: PChar;
var lpCredentials: TRasCredentials;
fRemovePassword: LongBool
): Longint; stdcall;

function RasConnectionNotification(
hrasconn: HRasConn;
hEvent: THandle;
dwFlags: Longint
): Longint; stdcall;

function RasGetSubEntryProperties(
lpszPhoneBook,
lpszEntry: PChar;
dwSubEntry: Longint;
var PRasSubEntry: TRasSubEntry;
var lpdwcb: Longint;
p: Pointer;
var lpdw: Longint
): Longint; stdcall;

function RasSetSubEntryProperties(
lpszPhoneBook,
lpszEntry: PChar;
dwSubEntry: Longint;
var PRasSubEntry: TRasSubEntry;
dwcb: Longint;
p: Pointer;
dw: Longint
): Longint; stdcall;

function RasGetAutodialAddress(
lpszAddress: PChar;
lpdwReserved: Pointer;
lpAutoDialEntries: PRasAutoDialEntry;
var lpdwcbAutoDialEntries: Longint;
var lpdwcAutoDialEntries: Longint
): Longint; stdcall;

function RasSetAutodialAddress(
lpszAddress: PChar;
dwReserved: Longint;
lpAutoDialEntries: PRasAutoDialEntry;
dwcbAutoDialEntries: Longint;
dwcAutoDialEntries: Longint
): Longint; stdcall;

function RasEnumAutodialAddresses(
lppAddresses: Pointer;
var lpdwcbAddresses: Longint;
var lpdwAddresses: Longint
): Longint; stdcall;

function RasGetAutodialEnable(
dwDialingLocation: Longint;
var lpfEnabled: LongBool
): Longint; stdcall;

function RasSetAutodialEnable(
dwDialingLocation: Longint;
fEnabled: LongBool
): Longint; stdcall;

function RasGetAutodialParam(
dwKey: Longint;
lpvValue: Pointer;
var lpdwcbValue: Longint
): Longint; stdcall;

function RasSetAutodialParam(
dwKey: Longint;
lpvValue: Pointer;
dwcbValue: Longint
): Longint; stdcall;
{$ELSE}
// This is a helper function to find if RNAPH.DLL is needed
function rnaph_needed: Boolean; // returns True if RNAPH.DLL is needed
{$ENDIF}

implementation

const
RAS_DLL = 'RASAPI32.DLL';

function RasCreatePhonebookEntry; external RAS_DLL name 'RasCreatePhonebookEntryA';
function RasDial; external RAS_DLL name 'RasDialA';
function RasEditPhonebookEntry; external RAS_DLL name 'RasEditPhonebookEntryA';
function RasEnumConnections; external RAS_DLL name 'RasEnumConnectionsA';
function RasEnumEntries; external RAS_DLL name 'RasEnumEntriesA';
function RasGetConnectStatus; external RAS_DLL name 'RasGetConnectStatusA';
function RasGetEntryDialParams; external RAS_DLL name 'RasGetEntryDialParamsA';
function RasGetErrorString; external RAS_DLL name 'RasGetErrorStringA';
function RasGetProjectionInfo; external RAS_DLL name 'RasGetProjectionInfoA';
function RasHangUp; external RAS_DLL name 'RasHangUpA';
function RasSetEntryDialParams; external RAS_DLL name 'RasSetEntryDialParamsA';

{$IFDEF WINVER41}
function RasEnumDevices; external RAS_DLL name 'RasEnumDevicesA';
function RasGetCountryInfo; external RAS_DLL name 'RasGetCountryInfoA';
function RasGetEntryProperties; external RAS_DLL name 'RasGetEntryPropertiesA';
function RasSetEntryProperties; external RAS_DLL name 'RasSetEntryPropertiesA';
function RasRenameEntry; external RAS_DLL name 'RasRenameEntryA';
function RasDeleteEntry; external RAS_DLL name 'RasDeleteEntryA';
function RasValidateEntryName; external RAS_DLL name 'RasValidateEntryNameA';
function RasGetSubEntryHandle; external RAS_DLL name 'RasGetSubEntryHandleA';
function RasGetCredentials; external RAS_DLL name 'RasGetCredentialsA';
function RasSetCredentials; external RAS_DLL name 'RasSetCredentialsA';
function RasConnectionNotification; external RAS_DLL name 'RasConnectionNotificationA';
function RasGetSubEntryProperties; external RAS_DLL name 'RasGetSubEntryPropertiesA';
function RasSetSubEntryProperties; external RAS_DLL name 'RasSetSubEntryPropertiesA';
function RasGetAutodialAddress; external RAS_DLL name 'RasGetAutodialAddressA';
function RasSetAutodialAddress; external RAS_DLL name 'RasSetAutodialAddressA';
function RasEnumAutodialAddresses; external RAS_DLL name 'RasEnumAutodialAddressesA';
function RasGetAutodialEnable; external RAS_DLL name 'RasGetAutodialEnableA';
function RasSetAutodialEnable; external RAS_DLL name 'RasSetAutodialEnableA';
function RasGetAutodialParam; external RAS_DLL name 'RasGetAutodialParamA';
function RasSetAutodialParam; external RAS_DLL name 'RasSetAutodialParamA';
{$ELSE}
{*
** but for now the functions without the type specifier must be implemented
** as follows (at least until rnaph.dll disappears...
*}
var
rnaph_initialized: Boolean = False;
is_rnaph: Boolean = False;
lib: HModule;

function rnaph_(const func: String): Pointer;
begin
if not rnaph_initialized then
begin
// Try first with RASAPI32.DLL
lib := LoadLibrary(RAS_DLL);
if lib <> 0 then
begin
Result := GetProcAddress(lib, PChar(func + 'A'));
if Result <> nil then
begin
rnaph_initialized := True;
Exit;
end;
end
else
raise Exception.Create('Error opening rasapi32.dll');
// function not found - try rnaph.dll
lib := LoadLibrary('rnaph.dll');
if lib <> 0 then
begin
Result := GetProcAddress(lib, PChar(func));
if Result <> nil then
begin
rnaph_initialized := True;
is_rnaph := True;
Exit;
end
else
raise Exception.Create('Function ' + func + ' not found!');
end
else
raise Exception.Create('Error opening rnaph.dll');
end
else
begin
if is_rnaph then
Result := GetProcAddress(lib, PChar(func))
else
Result := GetProcAddress(lib, PChar(func + 'A'));
if Result = nil then
raise Exception.Create('Function ' + func + ' not found!');
end;
end;

function rnaph_needed: Boolean;
var
sz: Longint;
begin
// Dumb call... just to obtain rnaph status...
RasGetCountryInfo(nil, sz);
Result := is_rnaph;
end;

function RasValidateEntryName(lpszPhonebook, szEntry: PAnsiChar): Longint;
var
f: Function(lpszPhonebook, szEntry: PAnsiChar): Longint; stdcall;
begin
@f := rnaph_('RasValidateEntryName');
Result := f(lpszPhonebook, szEntry);
end;

function RasRenameEntry(lpszPhonebook, szEntryOld, szEntryNew: PAnsiChar): Longint;
var
f: function(lpszPhonebook, szEntryOld, szEntryNew: PAnsiChar): Longint; stdcall;
begin
@f := rnaph_('RasRenameEntry');
Result := f(lpszPhonebook, szEntryOld, szEntryNew);
end;

function RasDeleteEntry(lpszPhonebook, szEntry: PAnsiChar): Longint;
var
f: function(lpszPhonebook, szEntry: PAnsiChar): Longint; stdcall;
begin
@f := rnaph_('RasDeleteEntry');
Result := f(lpszPhonebook, szEntry);
end;

function RasGetEntryProperties(lpszPhonebook, szEntry: PAnsiChar; lpbEntry: Pointer;
var lpdwEntrySize: Longint; lpbDeviceInfo: Pointer;
var lpdwDeviceInfoSize: Longint): Longint;
var
f: function(lpszPhonebook, szEntry: PAnsiChar; lpbEntry: Pointer;
var lpdwEntrySize: Longint; lpbDeviceInfo: Pointer;
var lpdwDeviceInfoSize: Longint): Longint; stdcall;
begin
@f := rnaph_('RasGetEntryProperties');
Result := f(lpszPhonebook, szEntry, lpbEntry, lpdwEntrySize, lpbDeviceInfo, lpdwDeviceInfoSize);
end;

function RasSetEntryProperties(lpszPhonebook, szEntry: PAnsiChar;
lpbEntry: Pointer; dwEntrySize: Longint; lpbDeviceInfo: Pointer;
dwDeviceInfoSize: Longint): Longint;
var
f: function(lpszPhonebook, szEntry: PAnsiChar;
lpbEntry: Pointer; dwEntrySize: Longint; lpbDeviceInfo: Pointer;
dwDeviceInfoSize: Longint): Longint; stdcall;
begin
@f := rnaph_('RasSetEntryProperties');
Result := f(lpszPhonebook, szEntry, lpbEntry, dwEntrySize, lpbDeviceInfo, dwDeviceInfoSize);
end;

function RasGetCountryInfo(lpCtryInfo: PRasCtryInfo;
var lpdwSize: Longint): Longint;
var
f: function(lpCtryInfo: PRasCtryInfo;
var lpdwSize: Longint): Longint; stdcall;
begin
@f := rnaph_('RasGetCountryInfo');
Result := f(lpCtryInfo, lpdwSize);
end;

function RasEnumDevices(lpBuff: PRasDevInfo; var lpcbSize: Longint;
var lpcDevices: Longint): Longint;
var
f: function(lpBuff: PRasDevInfo; var lpcbSize: Longint;
var lpcDevices: Longint): Longint; stdcall;
begin
@f := rnaph_('RasEnumDevices');
Result := f(lpBuff, lpcbSize, lpcDevices);
end;

initialization
finalization
if rnaph_initialized and is_rnaph then
FreeLibrary(lib);
{$ENDIF}
end.
 
多人接受答案了。
 
删除猫的驱动不就行了
 
后退
顶部