Internet - pegando catalogo de enderecos do Windows

Top  Previous  Next

This may help

 

procedure ChangeSettings;

var

Entry: PRasEntry;

FoundModem, EntryName, TheIPAddress, TheText:string;

Ini : TIniFile;

x,IsNameFree, TotalOptions:integer;

Res: Cardinal;

UserEntry: PRasDialParams;

Reg:TRegistry;

CompanyName:string;

ShowPasswordWarning:boolean;

DunToParse:string;

begin

if CheckDunInstalled = False then Exit;

ShowPasswordWarning:=False;

Ini:=TIniFile.Create(ParamStr(1));

CompanyName:=Ini.ReadString('Config''CompanyName''Error');

EntryName:=Ini.ReadString('DunEntry''EntryName''Error');

if EntryName = 'Error' then

begin

///Add error message here

Exit;

end

else

begin

x:=2;

IsNameFree:= CheckDunName(EntryName);

        while IsNameFree <> 0 do         //loop to add extra chars

        begin

        EntryName:= EntryName + IntToStr(x);

        Inc(x);

        IsNameFree:= CheckDunName(EntryName);

        end;

end;

 

FoundModem:= FindDunModem;

    if FoundModem = 'Error' then

        begin

        MessageBox (0,'Ninstall did not find a modem...', PChar('Update

Internet Settings For ' + CompanyName), mb_ok + MB_ICONQUESTION);

        Exit;

        end;

Entry := AllocMem(1768);

 

case Win32Platform of

        VER_PLATFORM_WIN32_WINDOWS:

        begin  //***Windows 9x/ME***//

        Entry := AllocMem(1768);

        Entry^.dwSize := 1768;

        Entry.dwFramingProtocol:= 1;

        StrPCopy(Entry.szDeviceType, 'modem');

        StrPCopy(Entry.szDeviceName, FoundModem);

        end;

        VER_PLATFORM_WIN32_NT:

        case Win32MajorVersion of

        3:begin

        end;

        4:begin //***Windows NT4***//

        Entry := AllocMem(1796);

        Entry^.dwSize := 1796 ;

        Entry.dwFramingProtocol:= 1;

        StrPCopy(Entry.szDeviceType, 'modem');

        StrPCopy(Entry.szDeviceName, FoundModem);

        end;

        5:begin  //***Windows 2000***//

        Entry := AllocMem(2088);

        Entry^.dwSize := 2088;

        StrPCopy(Entry.szDeviceType, 'RASDT_Modem');

        StrPCopy(Entry.szDeviceName, FoundModem);

        end;

        end;

end;

TotalOptions:=0;

if Ini.ReadString('DunEntry''UseCountryAndAreaCodes''No') = 'Yes' Then

TotalOptions:= TotalOptions + 1;

if Ini.ReadString('DunEntry''SpecificIpAddress''No') = 'Yes' Then

TotalOptions:= TotalOptions + 2;

if Ini.ReadString('DunEntry''SpecificNameServers''No') = 'Yes' Then

TotalOptions:= TotalOptions + 4;

if Ini.ReadString('DunEntry''IpHeaderCompression''No') = 'Yes' Then

TotalOptions:= TotalOptions + 8;

if Ini.ReadString('DunEntry''RemoteDefaultGateway''No') = 'Yes' Then

TotalOptions:= TotalOptions + 10;

if Ini.ReadString('DunEntry''DisableLcpExtensions''No') = 'Yes' Then

TotalOptions:= TotalOptions + 20;

if Ini.ReadString('DunEntry''TerminalBeforeDial''No') = 'Yes' Then

TotalOptions:= TotalOptions + 40;

if Ini.ReadString('DunEntry''TerminalAfterDial''No') = 'Yes' Then

TotalOptions:= TotalOptions + 80;

if Ini.ReadString('DunEntry''ModemLights''No') = 'Yes' Then

TotalOptions:= TotalOptions + 100;

if Ini.ReadString('DunEntry''SwCompression''No') = 'Yes' Then

TotalOptions:= TotalOptions + 200;

if Ini.ReadString('DunEntry''RequireEncryptedPw''No') = 'Yes' Then

TotalOptions:= TotalOptions + 400;

if Ini.ReadString('DunEntry''RequireMsEncryptedPw''No') = 'Yes' Then

TotalOptions:= TotalOptions + 800;

if Ini.ReadString('DunEntry''RequireDataEncryption''No') = 'Yes' Then

TotalOptions:= TotalOptions + 1000;

if Ini.ReadString('DunEntry''NetworkLogon''No') = 'Yes' Then

TotalOptions:= TotalOptions + 2000;

if Ini.ReadString('DunEntry''UseLogonCredentials''No') = 'Yes' Then

TotalOptions:= TotalOptions + 4000;

if Ini.ReadString('DunEntry''PromoteAlternates''No') = 'Yes' Then

TotalOptions:= TotalOptions + 8000;

 

case Win32Platform of

        VER_PLATFORM_WIN32_WINDOWS:

        begin  //***Windows 9x/ME***//

        Entry.dwfOptions:= TotalOptions;

        end;

        VER_PLATFORM_WIN32_NT:

        case Win32MajorVersion of

        4:begin //***Windows NT4***//

        Entry.dwfOptions:= TotalOptions;

        end;

        5:begin  //***Windows 2000***//

        Entry.dwfOptions:= TotalOptions;

        end;

        end;

end;

 

if Ini.ReadString('DunEntry''NetProtocols''Error') = 'TCP' then

Entry.dwfNetProtocols:= RASNP_Ip

else if Ini.ReadString('DunEntry''NetProtocols''Error') = 'IPX' then

Entry.dwfNetProtocols:= RASNP_Ipx

else if Ini.ReadString('DunEntry''NetProtocols''Error') = 'NetBEUI' then

Entry.dwfNetProtocols:= RASNP_NetBEUI

else

Entry.dwfNetProtocols:= RASNP_Ip;

 

if Ini.ReadString('DunEntry''FramingProtocol''Error') = 'PPP' then

Entry.dwFramingProtocol:=RASFP_Ppp

else if Ini.ReadString('DunEntry''FramingProtocol''Error') = 'SLIP' then

Entry.dwFramingProtocol:=RASFP_Slip

else if Ini.ReadString('DunEntry''FramingProtocol''Error') = 'Ras' then

Entry.dwFramingProtocol:=RASFP_Ras

else

Entry.dwFramingProtocol:=RASFP_Ppp;

 

Entry.dwFrameSize:= Ini.ReadInteger('DunEntry','FrameSize'1006);

 

TheIPAddress:= Ini.ReadString('DunEntry''IPAddress''0.0.0.0');

Entry.ipaddr.a:=StrToInt(Copy(TheIPAddress,0,Pos('.',TheIPAddress) - 1));

Delete(TheIPAddress,1,Pos('.',TheIPAddress));

Entry.ipaddr.b:=StrToInt(Copy(TheIPAddress,0,Pos('.',TheIPAddress) - 1));

Delete(TheIPAddress,1,Pos('.',TheIPAddress));

Entry.ipaddr.c:=StrToInt(Copy(TheIPAddress,0,Pos('.',TheIPAddress) - 1));

Delete(TheIPAddress,1,Pos('.',TheIPAddress));

Entry.ipaddr.d:=StrToInt(Copy(TheIPAddress,0,Length(TheIPAddress)));

 

TheIPAddress:= Ini.ReadString('DunEntry''IPAddressDNS''0.0.0.0');

Entry.ipaddrDns.a:=StrToInt(Copy(TheIPAddress,0,Pos('.',TheIPAddress) - 1));

Delete(TheIPAddress,1,Pos('.',TheIPAddress));

Entry.ipaddrDns.b:=StrToInt(Copy(TheIPAddress,0,Pos('.',TheIPAddress) - 1));

Delete(TheIPAddress,1,Pos('.',TheIPAddress));

Entry.ipaddrDns.c:=StrToInt(Copy(TheIPAddress,0,Pos('.',TheIPAddress) - 1));

Delete(TheIPAddress,1,Pos('.',TheIPAddress));

Entry.ipaddrDns.d:=StrToInt(Copy(TheIPAddress,0,Length(TheIPAddress)));

 

TheIPAddress:= Ini.ReadString('DunEntry''IPAddressDNSAlt''0.0.0.0');

Entry.ipaddrDnsAlt.a:=StrToInt(Copy(TheIPAddress,0,Pos('.',TheIPAddress) -

1));

Delete(TheIPAddress,1,Pos('.',TheIPAddress));

Entry.ipaddrDnsAlt.b:=StrToInt(Copy(TheIPAddress,0,Pos('.',TheIPAddress) -

1));

Delete(TheIPAddress,1,Pos('.',TheIPAddress));

Entry.ipaddrDnsAlt.c:=StrToInt(Copy(TheIPAddress,0,Pos('.',TheIPAddress) -

1));

Delete(TheIPAddress,1,Pos('.',TheIPAddress));

Entry.ipaddrDnsAlt.d:=StrToInt(Copy(TheIPAddress,0,Length(TheIPAddress)));

 

TheIPAddress:= Ini.ReadString('DunEntry''IPAddressWINS''0.0.0.0');

Entry.ipaddrWins.a:=StrToInt(Copy(TheIPAddress,0,Pos('.',TheIPAddress) -

1));

Delete(TheIPAddress,1,Pos('.',TheIPAddress));

Entry.ipaddrWins.b:=StrToInt(Copy(TheIPAddress,0,Pos('.',TheIPAddress) -

1));

Delete(TheIPAddress,1,Pos('.',TheIPAddress));

Entry.ipaddrWins.c:=StrToInt(Copy(TheIPAddress,0,Pos('.',TheIPAddress) -

1));

Delete(TheIPAddress,1,Pos('.',TheIPAddress));

Entry.ipaddrWins.d:=StrToInt(Copy(TheIPAddress,0,Length(TheIPAddress)));

 

TheIPAddress:= Ini.ReadString('DunEntry''IPAddressWINSAlt''0.0.0.0');

Entry.ipaddrWinsAlt.a:=StrToInt(Copy(TheIPAddress,0,Pos('.',TheIPAddress) -

1));

Delete(TheIPAddress,1,Pos('.',TheIPAddress));

Entry.ipaddrWinsAlt.b:=StrToInt(Copy(TheIPAddress,0,Pos('.',TheIPAddress) -

1));

Delete(TheIPAddress,1,Pos('.',TheIPAddress));

Entry.ipaddrWinsAlt.c:=StrToInt(Copy(TheIPAddress,0,Pos('.',TheIPAddress) -

1));

Delete(TheIPAddress,1,Pos('.',TheIPAddress));

Entry.ipaddrWinsAlt.d:=StrToInt(Copy(TheIPAddress,0,Length(TheIPAddress)));

 

if Ini.SectionExists('PopNumbers') then

        begin

DunToParse:=WinMain;

Trim(DunToParse);

Delete(DunToParse,1,Pos(' ',DunToParse));

StrPCopy(Entry.szLocalPhoneNumber, DunToParse);

MessageBox (0,PChar(DunToParse) , PChar(DunToParse) , mb_ok +

MB_ICONQUESTION);

        end

else

        begin

Entry.dwCountryID:= Ini.ReadInteger('DunEntry''CountryID'44);

Entry.dwCountryCode:= Ini.ReadInteger('DunEntry''CountryCode'44);

StrPCopy(Entry.szAreaCode, Ini.ReadString('DunEntry''AreaCode''020'));

StrPCopy(Entry.szLocalPhoneNumber, Ini.ReadString('DunEntry',

'LocalPhoneNumber''123456789'));

        end;

 

case Win32Platform of

        VER_PLATFORM_WIN32_WINDOWS:

        begin  //***Windows 9x/ME***//

        SetEntryProperties(EntryName, Entry, 1768);

        end;

        VER_PLATFORM_WIN32_NT:

        case Win32MajorVersion of

        4:begin //***Windows NT4***//

        SetEntryProperties(EntryName, Entry, 1796);

        end;

        5:begin  //***Windows 2000***//

        SetEntryProperties(EntryName, Entry, 2088);

        end;

        end;

end;

 

FreeMem(Entry);

 

begin

//***Set Username and Password***//

UserEntry := AllocMem(1052);

try

UserEntry.dwSize:=1052;

StrPCopy(UserEntry.szEntryName, EntryName);

StrPCopy(UserEntry.szCallbackNumber, '');

if Ini.ReadString('DunEntry''UserName''Error') <> 'Error' then

        begin

        StrPCopy(UserEntry.szUserName,Ini.ReadString('DunEntry''UserName',

'Error'));

        if Ini.ReadString('DunEntry''Password''Error') <> 'Error' then

        StrPCopy(UserEntry.szPassword,Ini.ReadString('DunEntry''Password',

'Error'));

        StrPCopy(UserEntry.szDomain,'');

        Res := RasSetEntryDialParams(nil, UserEntry, False);

        if Res <> 0 then

        begin

        ShowPasswordWarning:=True;

        end;

 

        end;

finally

FreeMem(UserEntry);

end;

 

if Win32Platform = VER_PLATFORM_WIN32_WINDOWS then

        begin

        if GetLocalUserName = '' then ShowPasswordWarning:= True;

        if IsMSNetworkClientInstalled <> True then

ShowPasswordWarning:=True;

        end;

//ShowWarning For Password

if ShowPasswordWarning <> False then

        begin

TheText:= 'Your password could not be stored' + Chr(13) + Chr(13) + 'Please

make a note for when to make your first connection' + Chr(13) + Chr(13);

TheText:= TheText + 'Username = ' + Ini.ReadString('DunEntry''UserName',

'Error') + Chr(13) + Chr(13);

TheText:= TheText + 'Password = ' + Ini.ReadString('DunEntry''Password',

'Error') + Chr(13) + Chr(13);

MessageBox (0,PChar(TheText), PChar('Update Internet Settings For ' +

CompanyName), mb_ok + MB_ICONQUESTION);

//if yes install msclient

        end;

end;

MessageBox (0,PChar(GetLocalUserName), PChar('GetLocalUserName'), mb_ok +

MB_ICONQUESTION);

 

DoAutoDial(Ini.ReadString('DUN''AutoDial''No'));

 

if Ini.ReadString('DunEntry''MakeDefault''No') = 'Yes' then

        begin

        Reg:=TRegistry.Create;

        Reg.RootKey := HKEY_CURRENT_USER;

        Reg.OpenKey('\RemoteAccess', True);

        Reg.WriteString('InternetProfile',EntryName);

        Reg.Free;

        end;

 

Ini.Free;

end;

 

--

 

Brian Slack

http://www.depicus.com

"Wake On Lan" and "Remote Shutdown" Software

 

Agency Manager - Estate Agency Software

http://www.agencymanager.co.uk

 

"Can you manage without it..."

"Caroll Ferkl" <Caroll.Ferkl@ntv.de> wrote in message

news:3d3f7cd2$1_1@dnews...

> I want to copy a RAS phonebook entry under special conditions. But I get

> always a compiler error with the parameter for RasGetEntryProperties() !

> Help, I'm blind!!!!

>

> Sorry, what's wrong with this?

>

> MfG

> C.

>

procedure TForm1.FormShow(Sender: TObject);

> var

>   OldDefConn, NewDefConn : TRasEntry; // Structure for Old / new

> Phonebookentry

>   i, BuffSize : LongInt;

>   Name : Pchar;

>

begin

>   DialUp.GetEntries;

>   ListBox.Items := DialUp.Entries;

>   for i:=0 to ListBox.Items.Count-1 do

>      begin

>        StrPCopy(Name,DialUp.Entries[i]);

>        RasGetEntryProperties(Nil,

>                              Name,

>                              @OldDefConn,

>                              BuffSize,

>                              Nil,

>                              0);

>        If TRasEntr.xy = then

>          begin

>    ......

>   end;

>      end//for

end;

>

////////////////////////// Structure: ///////////////////////////

>

> (*RASAPI*)(* Describes a RAS phonebook entry *)

> (*RASAPI*)  LPRasEntryA = ^TRasEntryA;

> (*RASAPI*)  TRasEntryA  = record

> (*RASAPI*)    dwSize,

> (*RASAPI*)    dwfOptions,

> (*RASAPI*)    dwCountryID,

> (*RASAPI*)    dwCountryCode          : Longint;

> (*RASAPI*)    szAreaCode             : array[0.. RAS_MaxAreaCode] of

> AnsiChar;

> (*RASAPI*)    szLocalPhoneNumber     : array[0..RAS_MaxPhoneNumber] of

> AnsiChar;

> (*RASAPI*)    dwAlternatesOffset     : Longint;

> (*RASAPI*)    ipaddr,

> (*RASAPI*)    ipaddrDns,

> (*RASAPI*)    ipaddrDnsAlt,

> (*RASAPI*)    ipaddrWins,

> (*RASAPI*)    ipaddrWinsAlt          : TRasIPAddr;

> (*RASAPI*)    dwFrameSize,

> (*RASAPI*)    dwfNetProtocols,

> (*RASAPI*)    dwFramingProtocol      : Longint;

> (*RASAPI*)    szScript               : Array[0..MAX_PATH - 1of AnsiChar;

> (*RASAPI*)    szAutodialDll          : Array [0..MAX_PATH - 1of

AnsiChar;

> (*RASAPI*)    szAutodialFunc         : Array [0..MAX_PATH - 1of

AnsiChar;

> (*RASAPI*)    szDeviceType           : Array [0..RAS_MaxDeviceType] of

> AnsiChar;

> (*RASAPI*)    szDeviceName           : Array [0..RAS_MaxDeviceName] of

AnsiC

> har;

> (*RASAPI*)    szX25PadType           : Array [0..RAS_MaxPadType] of

> AnsiChar;

> (*RASAPI*)    szX25Address           : Array [0..RAS_MaxX25Address] of

> AnsiChar;

> (*RASAPI*)    szX25Facilities        : Array [0..RAS_MaxFacilities] of

> AnsiChar;

> (*RASAPI*)    szX25UserData          : Array [0..RAS_MaxUserData] of

> AnsiChar;

> (*RASAPI*)    dwChannels,

> (*RASAPI*)    dwReserved1,

> (*RASAPI*)    dwReserved2            : Longint;

> (*RASAPI*)  end;

> (*RASAPI*)

> (*RASAPI*)  LPRasEntryW = ^TRasEntryW;

> (*RASAPI*)  TRasEntryW  = record

> (*RASAPI*)    dwSize,

> (*RASAPI*)    dwfOptions,

> (*RASAPI*)    dwCountryID,

> (*RASAPI*)    dwCountryCode          : Longint;

> (*RASAPI*)    szAreaCode             : array[0.. RAS_MaxAreaCode] of

> WideChar;

> (*RASAPI*)    szLocalPhoneNumber     : array[0..RAS_MaxPhoneNumber] of

> WideChar;

> (*RASAPI*)    dwAlternatesOffset     : Longint;

> (*RASAPI*)    ipaddr,

> (*RASAPI*)    ipaddrDns,

> (*RASAPI*)    ipaddrDnsAlt,

> (*RASAPI*)    ipaddrWins,

> (*RASAPI*)    ipaddrWinsAlt          : TRasIPAddr;

> (*RASAPI*)    dwFrameSize,

> (*RASAPI*)    dwfNetProtocols,

> (*RASAPI*)    dwFramingProtocol      : Longint;

> (*RASAPI*)    szScript               : Array[0..MAX_PATH - 1of WideChar;

> (*RASAPI*)    szAutodialDll          : Array [0..MAX_PATH - 1of

WideChar;

> (*RASAPI*)    szAutodialFunc         : Array [0..MAX_PATH - 1of

WideChar;

> (*RASAPI*)    szDeviceType           : Array [0..RAS_MaxDeviceType] of

> WideChar;

> (*RASAPI*)    szDeviceName           : Array [0..RAS_MaxDeviceName] of

> WideChar;

> (*RASAPI*)    szX25PadType           : Array [0..RAS_MaxPadType] of

> WideChar;

> (*RASAPI*)    szX25Address           : Array [0..RAS_MaxX25Address] of

> WideChar;

> (*RASAPI*)    szX25Facilities        : Array [0..RAS_MaxFacilities] of

> WideChar;

> (*RASAPI*)    szX25UserData          : Array [0..RAS_MaxUserData] of

> WideChar;

> (*RASAPI*)    dwChannels,

> (*RASAPI*)    dwReserved1,

> (*RASAPI*)    dwReserved2            : Longint;

> (*RASAPI*)  end;

> (*RASAPI*)

> (*RASAPI*)  LPRasEntry = ^TRasEntry;

> (*RASAPI*)  TRasEntry  = TRasEntryA;

> (*RASAPI*)

>

>

>

 

RasGetEntryProperties(Nil,

                      Name,

                      @OldDefConn,

                      BuffSize,

                      Nil,

                      0);

                                   

                                  function RasGetEntryPropertiesA(lpszPhonebook: PAnsiChar; lpszEntry:

PAnsiChar;  lpRasEntry: PRasEntryA; var lpdwEntryInfoSize: DWORD;

lpbDeviceInfo: Pointer; lpdwDeviceInfoSize: PDWORD): DWORD; stdcall;

 

 

I got my ras files from the Jedi site. Although the last example I sent was

long it does show one of the problems of ras. The RasEntry records vary in

size from O/S to O/S

 

I don't use RasGetentryProperties only RasSetEntryProperties.