delphi中怎样修改电脑的日期时间以及IP地址?
比较急,请教各位

解决方案 »

  1.   

    用api函数SetSystemTime修改系统时间
      

  2.   

    1)SetSystemTime
    2)修改注册表http://lysoft.7u7.net
      

  3.   

    2000/XP下改IP还可以是
    NetSH的WinExec调用具体看相关文档http://lysoft.7u7.net
      

  4.   

    var ToSetTime:TsystemTime;
    begin
      DateTimeToSystemTime(strtodatetime(Edit1.text),ToSetTime);
      if not setLocalTime(ToSetTime) then 
      showmessage('系统时间修改失败!请使用具有相应权限的帐号登陆windows!');
    end;
      

  5.   


      For Windows 9X/ME/NT/2000/XP:   The SetLocalTime function fails if the calling process does not have 
      the SE_SYSTEMTIME_NAME privilege. This privilege is disabled by default. 
      Use the AdjustTokenPrivileges function to enable this privilege. 
    } function SetPCSystemTime(dDateTime: TDateTime): Boolean; 
    const 
      SE_SYSTEMTIME_NAME = 'SeSystemtimePrivilege'; 
    var 
      hToken: THandle; 
      ReturnLength: DWORD; 
      tkp, PrevTokenPriv: TTokenPrivileges; 
      luid: TLargeInteger; 
      dSysTime: TSystemTime; 
    begin 
      Result := False; 
      if (Win32Platform = VER_PLATFORM_WIN32_NT) then 
      begin 
        if OpenProcessToken(GetCurrentProcess, 
          TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then 
        begin 
          try 
            if not LookupPrivilegeValue(nil, SE_SYSTEMTIME_NAME, luid) then Exit; 
            tkp.PrivilegeCount := 1; 
            tkp.Privileges[0].luid := luid; 
            tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED; 
            if not AdjustTokenPrivileges(hToken, False, tkp, SizeOf(TTOKENPRIVILEGES), 
              PrevTokenPriv, ReturnLength) then 
              Exit; 
            if (GetLastError <> ERROR_SUCCESS) then 
            begin 
              raise Exception.Create(SysErrorMessage(GetLastError)); 
              Exit; 
            end; 
          finally 
            CloseHandle(hToken); 
          end; 
        end; 
      end; 
      DateTimeToSystemTime(dDateTime, dSysTime); 
      Result := Windows.SetLocalTime(dSysTime); 
    end; {************************************************************} 
      

  6.   

    change the system time?  {1.}{
      For Windows 9X/ME/NT/2000/XP:  The SetLocalTime function fails if the calling process does not have
      the SE_SYSTEMTIME_NAME privilege. This privilege is disabled by default.
      Use the AdjustTokenPrivileges function to enable this privilege.
    }function SetPCSystemTime(dDateTime: TDateTime): Boolean;
    const
      SE_SYSTEMTIME_NAME = 'SeSystemtimePrivilege';
    var
      hToken: THandle;
      ReturnLength: DWORD;
      tkp, PrevTokenPriv: TTokenPrivileges;
      luid: TLargeInteger;
      dSysTime: TSystemTime;
    begin
      Result := False;
      if (Win32Platform = VER_PLATFORM_WIN32_NT) then
      begin
        if OpenProcessToken(GetCurrentProcess,
          TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then
        begin
          try
            if not LookupPrivilegeValue(nil, SE_SYSTEMTIME_NAME, luid) then Exit;
            tkp.PrivilegeCount := 1;
            tkp.Privileges[0].luid := luid;
            tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
            if not AdjustTokenPrivileges(hToken, False, tkp, SizeOf(TTOKENPRIVILEGES),
              PrevTokenPriv, ReturnLength) then
              Exit;
            if (GetLastError <> ERROR_SUCCESS) then
            begin
              raise Exception.Create(SysErrorMessage(GetLastError));
              Exit;
            end;
          finally
            CloseHandle(hToken);
          end;
        end;
      end;
      DateTimeToSystemTime(dDateTime, dSysTime);
      Result := Windows.SetLocalTime(dSysTime);
    end;{************************************************************}{2.}procedure TForm1.Button1Click(Sender: TObject);
    var
      SystemTime: TSystemTime;
      NewTime, NewDate: string;
    begin
      NewTime := '13:58:00';
      NewDate := '02.02.2001'; // or '02/02/01'
      DateTimeToSystemTime(StrToDate(NewDate) + StrToTime(NewTime), SystemTime);
      SetLocalTime(SystemTime);
      // Tell windows, that the Time changed!
      PostMessage(HWND_BROADCAST, WM_TIMECHANGE, 0, 0); // *
    end;{
     Windows 2000 and later: An application should not broadcast
     the WM_TIMECHANGE message because the system will broadcast
     this message when the application changes the system time.
    }{************************************************************}{3.}function SetSystemTime(DateTime: TDateTime): Boolean;
    { (c) by UNDO }
    var
      tSetDati: TDateTime;
      vDatiBias: Variant;
      tTZI: TTimeZoneInformation;
      tST: TSystemTime;
    begin
      GetTimeZoneInformation(tTZI);
      vDatiBias := tTZI.Bias / 1440;
      tSetDati := DateTime + vDatiBias;
      with tST do
      begin
        wYear := StrToInt(FormatDateTime('yyyy', tSetDati));
        wMonth := StrToInt(FormatDateTime('mm', tSetDati));
        wDay := StrToInt(FormatDateTime('dd', tSetDati));
        wHour := StrToInt(FormatDateTime('hh', tSetDati));
        wMinute := StrToInt(FormatDateTime('nn', tSetDati));
        wSecond := StrToInt(FormatDateTime('ss', tSetDati));
        wMilliseconds := 0;
      end;
      Result := Windows.SetSystemTime(tST);
    end;
      

  7.   

    设置IP地址
    shellexecute(handle,'','netsh interface ip set address ' + SRegedit +
                 'static 192.168.0.1 255.255.255.0 192.168.0.10 1',nil,nil,sw_hide)