Jump to content

LAN Toggle


Recommended Posts

$ret = LanToggle('Local Area Connection')
Select
 Case $ret = 1
  MsgBox(0, '', 'Done!')
 Case Else
  MsgBox(0, '', '"Lan Area Connection" is not available')
EndSelect
Func LanToggle($lanconnection)
 $status = ''
 $status_ = ''
 $objwmiservice = ObjGet ('winmgmts:\\localhost\root\CIMV2')
 $colitems = $objWMIService.ExecQuery ('SELECT * FROM Win32_NetworkAdapter', 'WQL', 0x10 + 0x20)
 If IsObj ($colitems) Then
  For $objitem In $colitems
   If String($objitem.netconnectionid) = $lanconnection Then
    $status = Not (Not ($objitem.netconnectionstatus))
    ExitLoop
   EndIf
  Next
 EndIf
 $shellapp = ObjCreate ('shell.application')
 $ocontrolpanel = $shellApp.Namespace (3)
 For $folderitem In $ocontrolpanel.items
  If $folderitem.name = 'Network Connections' Then
   For $folderitem In $folderitem.getfolder.items
    If StringLower($folderitem.name) = StringLower($lanconnection) Then
     For $verb in $folderitem.verbs
      If $verb.name = 'En&able' Or $verb.name = 'Disa&ble' Then
       $verb.doit
       $exitlantoggle = 0
       While $exitlantoggle = 0
        Sleep(1)
        $colitems = $objWMIService.ExecQuery ('SELECT * FROM Win32_NetworkAdapter', 'WQL', 0x10 + 0x20)
        If IsObj ($colitems) Then
         For $objitem In $colitems
          If String($objitem.netconnectionid) = $lanconnection Then
           $status_ = Not (Not ($objitem.netconnectionstatus))
          EndIf
          If $status = Not ($status_) Then
           $exitlantoggle = 1
           ExitLoop
          EndIf
         Next
        EndIf
       WEnd
       Return 1
      EndIf
     Next
    EndIf
   Next
  EndIf
 Next
 Return 0
EndFunc   ;==>LanToggle

Edited by psandu.ro
Link to comment
Share on other sites

People would like code to be placed in a code box:

$ret = LanToggle('Local Area Connection')

Select
    Case $ret = 1
        MsgBox(0, '', 'Done!')
    Case Else
        MsgBox(0, '', '"Lan Area Connection" is not available')
EndSelect


Func LanToggle($lanconnection)
    $status = ''
    $status_ = ''
    $objwmiservice = ObjGet ('winmgmts:\\localhost\root\CIMV2')
    $colitems = $objWMIService.ExecQuery ('SELECT * FROM Win32_NetworkAdapter', 'WQL', 0x10 + 0x20)
    If IsObj ($colitems) Then
        For $objitem In $colitems
            If String($objitem.netconnectionid) = $lanconnection Then
                $status = Not (Not ($objitem.netconnectionstatus))
                ExitLoop
            EndIf
        Next
    EndIf
    $shellapp = ObjCreate ('shell.application')
    $ocontrolpanel = $shellApp.Namespace (3)
    For $folderitem In $ocontrolpanel.items
        If $folderitem.name = 'Network Connections' Then
            For $folderitem In $folderitem.getfolder.items
                If StringLower($folderitem.name) = StringLower($lanconnection) Then
                    For $verb in $folderitem.verbs
                        If $verb.name = 'En&able' Or $verb.name = 'Disa&ble' Then
                            $verb.doit
                            $exitlantoggle = 0
                            While $exitlantoggle = 0
                                Sleep(1)
                                $colitems = $objWMIService.ExecQuery ('SELECT * FROM Win32_NetworkAdapter', 'WQL', 0x10 + 0x20)
                                If IsObj ($colitems) Then
                                    For $objitem In $colitems
                                        If String($objitem.netconnectionid) = $lanconnection Then $status_ = Not (Not ($objitem.netconnectionstatus))
                                        If $status = Not ($status_) Then
                                            $exitlantoggle = 1
                                            ExitLoop
                                        EndIf
                                    Next
                                EndIf
                            WEnd
                            Return 1
                        EndIf
                    Next
                EndIf
            Next
        EndIf
    Next
    Return 0
EndFunc   ;==>LanToggle

Use the tags:

 

#)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...