就修改本机的IP,代码如下,单个对注册表里的键值进行修改,网卡属性里又会马上显示出来,但用程序运行修改后,注册表里的数据是改过来了,但打开网卡属性,里面却什么都没有了!不知道是为什么!请教一下了!Procedure IPAdss;
var
  Reg:TRegistry;
begin
  Reg:=TRegistry.Create;
  Reg.RootKey:=HKEY_LOCAL_MACHINE;
  Reg.OpenKey(sTCPIPRegKey,true);
  Reg.WriteString('IPAddress',Form1.ipads.Text);//ipads:TEdit
  Reg.CloseKey;
end;Procedure SubNetMask;
var
  Reg:TRegistry;
begin
  Reg:=TRegistry.Create;
  Reg.RootKey:=HKEY_LOCAL_MACHINE;
  Reg.OpenKey(sTCPIPRegKey,true);
  Reg.WriteString('SubNetMask',Form1.ipmask.Text);//ipmask:TEdit
  Reg.CloseKey;
end;Procedure DefaultGateway;
var
  Reg:TRegistry;
begin
  Reg:=TRegistry.Create;
  Reg.RootKey:=HKEY_LOCAL_MACHINE;
  Reg.OpenKey(sTCPIPRegKey,true);
  Reg.WriteString('DefaultGateway',Form1.gateway.Text);//gateway:TEdit
  Reg.CloseKey;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
  IPAdss;
  SubNetMask;
  DefaultGateway;
  ShutDownSystem(EWX_REBOOT);//调用另一个过程重启计算机,
end;因为还要修改计算机名,所以要重启一次计算机,

解决方案 »

  1.   

    好象不是修改注册表那么简单吧
    我当时为了得到ip 地址用的windows的api函数
    注册表的键值有很多个键是ip地址,你知道应该修改哪一个?
      

  2.   

    地址应该没问题,我前面有判断WINDOWS系统的代码NT内核的地址是'\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\' + GetNetCardServiceName;其中GetNetCardServiceName是获取网卡的函数
    我在注册表里单独对那条键值进行修改没问题,网卡属性里也反映出来了,但用程序修改,注册表里的属性是改过来了,但网卡属性里却什么都没有,空白。不知道什么原因
      

  3.   

    得到IP用的API函数我知道,但要修改的话应该用哪个API函数?
      

  4.   

    public
        function GetWinVer:Byte;//获取windows操作系统版本
        function SetPrivilege(PrivilegeName:String; Enable:Boolean):Boolean;//设置系统权限
        procedure ShutDownSystem(EWX_Type:Integer);
        function GetNetCardServiceName:String;
      end;var
      Form1: TForm1;
      inifile: TInifile;
      reg  : TRegistry;
      SubKeyList:TStringList;
      sTCPIPRegKey:string;
    implementation{$R *.dfm}const
      EWX_FORCE=4;     //强制关闭所有程序
      EWX_LOGOFF=0;    //注销
      EWX_SHUTDOWN=1;  //关闭计算机
      EWX_REBOOT=2;    //重启计算机
      EWX_POWEROFF=8;  //关闭系统并切断电源function TForm1.GetWinVer:Byte;
    var
      OS:TOSVersionInfo;
    begin
      OS.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
      GetVersionEx(OS);
      case OS.dwPlatformId of
        VER_PLATFORM_WIN32S        : Result:=0;//windows 3.1x/32s
        VER_PLATFORM_WIN32_WINDOWS : Result:=1;//windows 95
        VER_PLATFORM_WIN32_NT      : Result:=2;//windows NT
      end;
    end;function TForm1.SetPrivilege(PrivilegeName:String;Enable:Boolean):Boolean;
    var
      NewState,PreviousState : TTokenPrivileges;
      Token    : THandle;
      dwRetLen : DWord;
    begin
      Result :=False;
      OpenProcessToken(GetCurrentProcess,TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,token);
      NewState.PrivilegeCount := 1;
      if (LookupPrivilegeValue(nil,PChar(PrivilegeName),NewState.Privileges[0].LUID)) then
      begin
        if Enable then
          NewState.Privileges[0].Attributes:=SE_Privilege_Enabled
        else
          NewState.Privileges[0].Attributes:=0;
          dwRetLen:=0;
          Result:=AdjustTokenPrivileges(token,False,NewState,SizeOf(PreviousState),PreviousState,dwRetLen);
      end;
      CloseHandle(token);
    end;Procedure TForm1.ShutDownSystem(EWX_Type:Integer);
    begin
      if GetWinVer=2 then
      begin
        SetPrivilege('SeShutDownPrivilege',True);//提升系统权限到可以关机
        if (not ExitWindowsEx(EWX_Type,0)) then
        SetPrivilege('SeShutDownPrivilege',False);//如果关机不成功,将权限设置回去
      end
      else//如果内核是WIN 9X,或其他,则直接调用API函数
      ExitWindowsEx(EWX_Type,0);
    end;function  TForm1.GetNetCardServiceName:String;
    var
      Reg:TRegistry;
      i:Integer;
      sNetCardRegKey:String;
    begin
      Result:='';
      Reg:=TRegistry.Create;
      Reg.RootKey:=HKEY_LOCAL_MACHINE;
      sNetCardRegKey:='\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards';
      try
        Reg.OpenKeyReadOnly(sNetCardRegKey);
        SubKeyList:=TStringList.Create;
        Reg.GetKeyNames(SubKeyList);
        for i:=0 to SubKeyList.Count-1 do
        begin
          Reg.OpenKeyReadOnly(sNetCardRegKey+'\'+SubKeyList.Strings[i]);
          if Reg.ValueExists('ServiceName') then
          begin
            Result:=Reg.ReadString('ServiceName');
            break;
          end;
        end;
      finally
        Reg.CloseKey;
        Reg.Free;
        SubKeyList.Free;
      end;
      if Result='' then
      ShowMessage('网卡设置存在问题:网卡驱动程序错误或网卡未安装.');
    end;
    大致上都在这了