新建网络连接解决思路

新建网络连接
Hi,all

          有没有人知道怎样调用windows   API在网络邻居中新建一个LAN连接或者串口连接??谢谢,知道的告诉下过程及API

------解决方案--------------------
1。创建新的拨号连接。
参数:
hwn PROCEDURE TForm1.button1click(Sender:TObject);
VAR dwhandle:word;
aaa:integer;
begin
aaa:=getactivewindow();
dwResult:=RasCreatePhonebookEntryA(handle, ' ');
或DWresult:=RasCreatePhonebookEntryA(aaa, ' ');
if dwResult=0 then
memo1.lines.add( '新建拨号连接成功! ')
ELSE
memo1.lines.add( '新建拨号连接失败! ')

end;
2.修改指定拨号连接的属性。
Function RasEditPhonebookEntryA(hwnd:Thandle;lpszPhonebook:pchar;lpszEntryName:pchar):Dword;
stdcall; {位于Interface的USES 下 TYPE。。。end 之外}
lpszEntryName(pchar):要修改的拨号连接的名称,如‘163’,‘169’等。
函数返回值:0表示成功,否则为错误。
例:PROcedure TForm1.button2click(Sender:TObject);
如上。
3.获取当前系统中可用的拨号连接名称.。
在建立了拨号连接后,WIN9X将拨号连接的名称和属性写了注册表中,我们可以从注册表中可用的拨号连接名称
及InterNet Explorer中的默认连接名称。
在注册表的HKEY_USERS\.DEFAULT\RemoteACess\Address下,列出了已经在拨号网络中建立的拨号连接
的名称及其属性设置,其中各项目的名称即为可用的拨号连接的名称;各项目的值即为各连接的属性设置.
如果在InterNet Explorer 中设置了默认连接名称(Internet 选项=> > 连接=> > 设置=> > 使用以下拨号网络连接)
则在注册表的HKEY_USERS\.Default\RemoteAcess下,有一个字符串类型的键值,键值名InternetProfile,其值
即为Internet Explorer中设置的默认连接名称.
{在Uses中增加Registry单元,用于操作注册表}
procedure TForm1.button3click(Sender:TObject);
var
registrytemp:TRegistry;
stringtemp:TStringlist;
intindex:integer;
begin
registrytemp:=TRegistry.Create;
stringTemp:=Tstringlist.Create;
with registryTemp DO
BEGIN
RootKey:=HKEY_USERS; //根键置为HKEY_USERS
//如果存在于子键.Default\RemoteAccess\Addresses
if OpenKey( '.Default\RemoteAccess\Addresses ',false) then
getValueNames(stringsTemp); //读出各项目的名称,即拨号连接名称
closekey;
end;
memo1.lines.add( '************当前系统中有 '+IntTostr(stringsTemp.count) '
+ '各可用的拨号连接如下****** ');
for intindex:=0 to stringsTemp.count-1 do
memo1.lines.add(stringstemp.strings[intindex]); //列出Internet explorer中默认连接名称.
if registrytemp.Openkey( '.Default\RemoteAccess\Addresses ',false ') then
mome1.lines.add( 'Internet explorer中默认连接名称为 '+Registry.readstring( 'InternetProfile '));
//释放内存
RegistryTemp.free;
StringsTemp.free;
end;
4.用指定的拨号连接拨号
winexec( 'rundll32.exe rnaui.dll,RnaDial 163 ',SW_SHOWNORMAL);
其中字符串中的最后一个参数 '163 '为拨号连接的名称.
Procedure TForm1.botton4click(Sender:TObject);
var
strDiaName:string;
begin
strDiaName:= '163 ';
memo1.lines.add( '*****用拨号连接 '+strDiaName+ '实现拨号上网****** ');