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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.