Einzelnen Beitrag anzeigen

Astat

Registriert seit: 2. Dez 2009
Ort: München
320 Beiträge
 
Lazarus
 
#2

Re: Internet Verebindung sperren

  Alt 26. Jan 2010, 23:01
Zitat von Pluto:
zu Fuss geht das so: ....
Hallo Pluto, im Source so.

Delphi-Quellcode:

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Variants, Shell32_TLB, StdCtrls, ActiveX, ComObj, UrlMon;


// Shell32_TLB aus shell32.dll TLB ('Microsoft Shell Controls and Automation')
// wird benötigt --> Project|Import Type Library,
// ************************************************************************
// LIBID: {50A7E9B0-70EF-11D1-B75A-00A0C90564FE}

function LAN_ON_OFF(const ConnectionName: string): Boolean;
var
  ShellApp: Shell32_tlb.Shell;
  ControlPanel: Shell32_tlb.Folder;
  FolderItem: Shell32_tlb.FolderItem;
  NetworkFolder: Shell32_tlb.Folder;
  LANConnection: Shell32_tlb.FolderItem;
  EnableVerbItem, DisableVerbItem: Shell32_tlb.FolderItemVerb;
  I: Integer;
  LANEnable: Boolean;
begin
  LANEnable := false;
  ShellApp := CoShell.Create;
  ControlPanel := ShellApp.NameSpace(ssfCONTROLS);
  for I := 0 to ControlPanel.Items.Count - 1 do begin
    FolderItem := ControlPanel.Items.Item(I);
    if (FolderItem.Name = 'Network Connections') or
       (FolderItem.Name = 'Netzwerk- und DFÜ-Verbindungen') or
       (FolderItem.Name = 'Network and Dial-up Connections') or
       (FolderItem.Name = 'Network and Sharing Center') then
    begin
      NetworkFolder := FolderItem.GetFolder as Folder;
      Break;
    end;
  end;

  if NetworkFolder <> nil then begin
    for I := 0 to NetworkFolder.Items.Count - 1 do begin
      FolderItem := NetworkFolder.Items.Item(I);
      if FolderItem.Name = ConnectionName then begin
        LANConnection := FolderItem;
        Break;
      end;
    end;

    if LANConnection <> nil then begin
      for I := 0 to LANConnection.Verbs.Count - 1 do begin
        if (LANConnection.Verbs.Item(I).Name = '&Aktivieren') or
           (LANConnection.Verbs.Item(I).Name = 'En&able') then
        begin
          EnableVerbItem := LANConnection.Verbs.Item(I);
          LANEnable := True;
          Break;
        end else
        if (LANConnection.Verbs.Item(I).Name = '&Deaktivieren') or
           (LANConnection.Verbs.Item(I).Name = 'Disa&ble') then
        begin
          DisableVerbItem := LANConnection.Verbs.Item(I);
          LANEnable := False;
          Break;
        end;
      end;
      if LANEnable then EnableVerbItem.DoIt else DisableVerbItem.DoIt;
      Result := True;
    end;
  end;
end;

//-- How to use
procedure TForm1.Button1Click(Sender: TObject);
begin
  LAN_ON_OFF('LAN-Verbindung 2');
end;
Achtung OS Sprachabhängig!

lg. Astat
Angehängte Dateien
Dateityp: pas shell32_tlb_196.pas (53,2 KB, 20x aufgerufen)
Lanthan Astat
06810110811210410503210511511603209711003210010110 9032084097103
03211611111604403209711003210010110903210010510103 2108101116122
11610103209010110510810103206711110010103210511003 2068101108112
10410503210310111509910411410510109810111003211910 5114100046
  Mit Zitat antworten Zitat