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;