1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, WinInet, StdCtrls, Registry, Shellapi;
type TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure MyHangUp; const RasApi32 = 'RasApi32.dll'; RAS_MaxEntryName = 256; RAS_MaxDeviceType = 16; RAS_MaxDeviceName = 128;
DeviceType : PChar = 'modem';
type
RASCONN = record dwSize: DWORD; hrasconn: THandle; szEntryName: array [0..RAS_MaxEntryName] of Char; szDeviceType: array [0..RAS_MaxDeviceType] of Char; szDeviceName: array [0..RAS_MaxDeviceName] of Char; end;
ArrayRASCONN = array[1..7] of RASCONN; // if You have no more than 7 connections
LPRASCONN = ^ArrayRASCONN;
TRasEnumConnections = function(lprasconn: LPRASCONN; lpcb: LPDWORD; lpcConnections: LPDWORD):DWORD; stdcall; TRasHangUp = function(hrasconn: THandle):DWORD; stdcall;
var RasEnumConnections: TRasEnumConnections; RasHangUp : TRasHangUp;
hLib : THandle; ARasConn: ArrayRASCONN; Sz, Connections, Rez: DWord; lpVersionInformation: TOSVersionInfo; Counter: Integer; Ver: Boolean;
begin
FillChar(lpVersionInformation, SizeOf(lpVersionInformation), 0); lpVersionInformation.dwOSVersionInfoSize := SizeOf(lpVersionInformation); GetVersionEx(lpVersionInformation); Ver := lpVersionInformation.dwPlatformId >= VER_PLATFORM_WIN32_WINDOWS ;
if not Ver then // verify RAS functions enable with Windows version begin Exit; end;
hLib := LoadLibrary(PChar(RasApi32)); try
@RasEnumConnections := GetProcAddress(hLib,PChar('RasEnumConnectionsA')); @RasHangUp := GetProcAddress(hLib, PChar('RasHangUpA'));
FillChar(ARasConn, SizeOf(ARasConn), 0); ARasConn[1].dwSize := SizeOf(RASCONN);
Sz := SizeOf(ARasConn) ; Rez := 0; Connections := 0;
// Get Active Connections if Assigned(RasEnumConnections) then Rez := RasEnumConnections(@ARasConn, @Sz, @Connections);
if Assigned(RasHangUp) and (Rez = 0) and (Connections > 0) then for Counter := 1 to Connections do if StrComp(DeviceType, ARasConn[Counter].szDeviceType) = 0 then RasHangUp(ARasConn[Counter].hrasconn); finally FreeLibrary(hLib); end; end;
procedure inetstarten; var dwConnectionTypes: DWORD; begin dwConnectionTypes := INTERNET_CONNECTION_MODEM + INTERNET_CONNECTION_LAN + INTERNET_CONNECTION_PROXY; if not InternetGetConnectedState(@dwConnectionTypes, 0) then // not connected if not InternetAutodial(INTERNET_AUTODIAL_FORCE_ONLINE or INTERNET_AUTODIAL_FORCE_UNATTENDED, 0) then begin // error end;
end;
procedure TForm1.Button1Click(Sender: TObject); begin while not 0<>0 do begin application.ProcessMessages; inetstarten; ShellExecute(Handle, 'open', PChar(Edit1.Text), nil, nil, SW_SHOW); MyHangUp; end;
end; procedure TForm1.Button2Click(Sender: TObject); begin close; end;
end. |