teryx510 has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I've been working on a way to enable/disable my windows networking adapters. I found a few scripts out on the web which do the same thing only in vbscript and began working from there.
My script does work...sometimes. It always seems to disable the adapter but most of the time it cannot enable the adapter. Results seem to vary machine to machine on whether enabling works, though it appears that on most, it doesn't work.
I still consider myself a noobie and so I humbly ask for your help in resolving this problem.
use strict; use Win32::OLE("in"); $Win32::OLE::Warn = 3; my $Adapter = 'Local Area Connection'; AdapterReset(); sub AdapterReset { my $OShellConnection = Win32::OLE->new("Shell.Application") or die + "Failure to get Shell.Application." .Win32::OLE->LastError(). "\n"; my $Folder; my ($NetConn, $NetConns); my $NetAdapter; my $verb; my $OShellConnectionControlPanel = $OShellConnection->NameSpace(3) +; foreach $Folder (in $OShellConnectionControlPanel->{Items}) { if($Folder->Name eq "Network Connections") { $NetConns = $Folder->GetFolder; } } if($NetConns == '') { TimedMsg("Network Connections not found"); die "Network Connections not found"; } foreach $NetConn (in $NetConns->{Items}) { if($NetConn->{Name} eq $Adapter) { $NetAdapter = $NetConn; } } if($NetAdapter eq "") { die "$Adapter could not be found."; } foreach $verb (in $NetAdapter->{Verbs}) { if($verb->{Name} eq "En&able") { eval { $verb->DoIt or die print "Failed to Enable ".$verb-> +LastError(). "\n";} } elsif ($verb->{Name} eq "Disa&ble") { eval { $verb->DoIt or die print "Failed to Disable ".$verb- +>LastError(). "\n";} } } if ($@) { print "An error occurred ($@), continuing\n"; } }
I have thus far only only been able to get the following error back:
An error occurred (Win32::OLE(0.1709) error 0x80020011: "Does not support a collection"
in METHOD/PROPERTYGET ""
Ideas?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using OLE to enable/disable network adapters in Windows
by Gangabass (Vicar) on Oct 02, 2009 at 15:45 UTC | |
by teryx510 (Novice) on Oct 02, 2009 at 16:17 UTC | |
by Sinistral (Monsignor) on Oct 02, 2009 at 16:57 UTC | |
by Anonymous Monk on Oct 02, 2009 at 18:04 UTC | |
|
Re: Using OLE to enable/disable network adapters in Windows
by Bloodnok (Vicar) on Oct 02, 2009 at 20:02 UTC | |
by teryx510 (Novice) on Oct 02, 2009 at 22:31 UTC | |
by Anonymous Monk on Oct 03, 2009 at 00:52 UTC | |
by teryx510 (Novice) on Oct 05, 2009 at 13:27 UTC |