Sign in to follow this  
Followers 0
SandelPerieanu

LAN Toggle

2 posts in this topic

#1 ·  Posted (edited)

$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

Share this post


Link to post
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:

 

#)

Share this post


Link to post
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
Sign in to follow this  
Followers 0