IP更改成功,但是在网卡的INTERNET 协议(TCP/IP)属性-->[高级]的IP地址列里面除了一条正常的记录还有4条乱码记录,不知道是什么原因造成的而且用PING时发现GATEWAY 还是原来的请高手分析:谢谢!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
部分代码如下...............
var
..................
Reg: TRegistry;
filename:string;
key_str:string;
phKey:hKey;
lc_active_card,lc_card_address:string;
lc_ip,lc_submask,lc_gateway,lc_dns1,lc_dns2,lc_dns:string;
pValueName: array[0..255] of char;
pNewValue: array[0..255] of char;
begin
......................
lc_ip := TRIM(IP1.Text);
lc_submask := TRIM(SUBMASK1.Text);
lc_gateway := TRIM(GATEWAY1.Text);
lc_dns1 := TRIM(DNS11.Text);
lc_dns2 := TRIM(DNS12.Text);
......................
lc_dns := lc_dns1;
If lc_dns2 ='' Then
lc_dns := lc_dns2
else
Begin
If lc_dns1 <> lc_dns2 then lc_dns := lc_dns + ',' + lc_dns2;
End;
...................
lc_card_address := Trim(Reg.ReadString('ServiceName'))
....................
RegOpenKey(HKEY_LOCAL_MACHINE,pchar('SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\'+lc_card_address),phKey);
StrPCopy(pValueName,'IPAddress');
StrPCopy(pNewValue,lc_ip);
RegSetValueEx(phKey, @pValueName, 0, REG_MULTI_SZ, @pNewValue, StrLen(pNewValue));
RegFlushKey(phKey);
StrPCopy(pValueName,'SubnetMask');
StrPCopy(pNewValue,lc_submask);
RegSetValueEx(phKey, @pValueName, 0, REG_MULTI_SZ, @pNewValue, StrLen(pNewValue));
RegFlushKey(phKey);
StrPCopy(pValueName,'DefaultGateway');
StrPCopy(pNewValue,lc_gateway);
RegSetValueEx(phKey, @pValueName, 0, REG_MULTI_SZ, @pNewValue, StrLen(pNewValue));
RegFlushKey(phKey);
...............
Reg := TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKey('\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\'+lc_card_address, False) then
begin
Reg.WriteString('NameServer',Trim(lc_dns));
end;
Reg.CloseKey;
部分代码如下...............
var
..................
Reg: TRegistry;
filename:string;
key_str:string;
phKey:hKey;
lc_active_card,lc_card_address:string;
lc_ip,lc_submask,lc_gateway,lc_dns1,lc_dns2,lc_dns:string;
pValueName: array[0..255] of char;
pNewValue: array[0..255] of char;
begin
......................
lc_ip := TRIM(IP1.Text);
lc_submask := TRIM(SUBMASK1.Text);
lc_gateway := TRIM(GATEWAY1.Text);
lc_dns1 := TRIM(DNS11.Text);
lc_dns2 := TRIM(DNS12.Text);
......................
lc_dns := lc_dns1;
If lc_dns2 ='' Then
lc_dns := lc_dns2
else
Begin
If lc_dns1 <> lc_dns2 then lc_dns := lc_dns + ',' + lc_dns2;
End;
...................
lc_card_address := Trim(Reg.ReadString('ServiceName'))
....................
RegOpenKey(HKEY_LOCAL_MACHINE,pchar('SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\'+lc_card_address),phKey);
StrPCopy(pValueName,'IPAddress');
StrPCopy(pNewValue,lc_ip);
RegSetValueEx(phKey, @pValueName, 0, REG_MULTI_SZ, @pNewValue, StrLen(pNewValue));
RegFlushKey(phKey);
StrPCopy(pValueName,'SubnetMask');
StrPCopy(pNewValue,lc_submask);
RegSetValueEx(phKey, @pValueName, 0, REG_MULTI_SZ, @pNewValue, StrLen(pNewValue));
RegFlushKey(phKey);
StrPCopy(pValueName,'DefaultGateway');
StrPCopy(pNewValue,lc_gateway);
RegSetValueEx(phKey, @pValueName, 0, REG_MULTI_SZ, @pNewValue, StrLen(pNewValue));
RegFlushKey(phKey);
...............
Reg := TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKey('\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\'+lc_card_address, False) then
begin
Reg.WriteString('NameServer',Trim(lc_dns));
end;
Reg.CloseKey;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货