Einzelnen Beitrag anzeigen

GeorgPeifer

Registriert seit: 7. Dez 2004
Ort: Kerpen
21 Beiträge
 
#12

Re: eigene ip adresse ändern

  Alt 13. Okt 2005, 11:06
Erst Betriebssystem rausfinden (Zur Sicherheit), dann mit WinExec netsh aufrufen - habs nur mit XP getestet...

Delphi-Quellcode:
const
  { operating system (OS)constants }
  cOsUnknown = -1;
  cOsWin95 = 0;
  cOsWin98 = 1;
  cOsWin98SE = 2;
  cOsWinME = 3;
  cOsWinNT = 4;
  cOsWin2000 = 5;
  cOsXP = 6;

function GetOperatingSystem: Integer;
var
  osVerInfo: TOSVersionInfo;
  majorVer, minorVer: Integer;
begin
  Result := cOsUnknown;
  { set operating system type flag }
  osVerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
  if GetVersionEx(osVerInfo) then
  begin
    majorVer := osVerInfo.dwMajorVersion;
    minorVer := osVerInfo.dwMinorVersion;
    case osVerInfo.dwPlatformId of
      VER_PLATFORM_WIN32_NT: { Windows NT/2000 }
        begin
          if majorVer <= 4 then
            Result := cOsWinNT
          else if (majorVer = 5) and (minorVer = 0) then
            Result := cOsWin2000
          else if (majorVer = 5) and (minorVer = 1) then
            Result := cOsXP
          else
            Result := cOsUnknown;
        end;
      VER_PLATFORM_WIN32_WINDOWS: { Windows 9x/ME }
        begin
          if (majorVer = 4) and (minorVer = 0) then
            Result := cOsWin95
          else if (majorVer = 4) and (minorVer = 10) then
          begin
            if osVerInfo.szCSDVersion[1] = 'Athen
              Result := cOsWin98SE
            else
              Result := cOsWin98;
          end
          else if (majorVer = 4) and (minorVer = 90) then
            Result := cOsWinME
          else
            Result := cOsUnknown;
        end;
      else
        Result := cOsUnknown;
    end;
  end
  else
    Result := cOsUnknown;
end;

function WindowsDirectory:string;
var WinDir : PChar;
begin
  WinDir:=StrAlloc(Max_Path);
  try
    GetWindowsDirectory(WinDir,Max_Path);
    Result:=(String(WinDir))+'\';
  finally
    StrDispose(WinDir);
  end;
end; {WindowsDirectory}


procedure TForm1.IPLabelClick(Sender: TObject);
var windir:string;
    os:integer;
begin
  os:=GetOperatingSystem;
  If os=cOsWin95 then exit;
  If os=cOsWin98 then exit;
  If os=cOsWin98SE then exit;
  If os=cOsWinME then exit;
  If os=cOsWinNT then windir:=WindowsDirectory+'system32\';
  If os=cOsWin2000 then windir:=WindowsDirectory+'system32\';
  If os=cOsXP then windir:=WindowsDirectory+'system32\';
  WinExec(PChar(windir+'netsh interface ip set address name = "LAN-Verbindung" source = static addr = 192.168.1.28 mask = 255.255.255.0'),SW_SHOWNORMAL);
end;
Georg Peifer
  Mit Zitat antworten Zitat