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?
In reply to Using OLE to enable/disable network adapters in Windows by teryx510
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |