Jump to content

XP Sp3, monitor lan connect, restart adapter on hangup ?


Recommended Posts

I found this on another post but was wondering if this could be turned into a script that would monitor the wired lan connection for hangups and then disable and renable the lan adapter automatically.  For whatever reason on my winxp pc at work at some point in the evening it hangs on it's lan connection.  When I try to connect remotely I can't because of the loss of local area connection although the Icon on theh pc still shows it as connected.  The only way I can fix it, is either reboot the PC or disable and renable the lan adapter (which I can't do remotely).  So is there a script that would be able to do this using perhaps some of the code from below.  I tried the script from another post geared towards windows 7 to "automagically" diable and restart the adapter but it didn't seem to solve my problem.  

 

Any help appreciated.......newbie to all of this by the way.  

 

; Disable and Enable a Network card using 'Shell.Application'
;
; See also: <a href='[url=http://blog.mvpcn.net/icuc88/articles/244.aspx]http://blog.mvpcn.net/icuc88/articles/244.aspx[/url]' class='bbc_url' title='External link' rel='nofollow [url=external%27]external'>http://blog.mvpcn.net/icuc88/articles/244.aspx</a>[/url]
;
; To do: Rewrite this into a UDF. Parameters: $oLanConnection and $bEnabled
 
 
$oLanConnection = "Local Area Connection"; Change this to the name of the adapter to be disabled !
$bEnable = true             ; Change this to 'false' to DISABLE the network adapter
 
if @OSType<>"WIN32_NT" then
    Msgbox(0,"","This script requires Windows 2000 or higher.")
    exit
endif
 
 
if @OSVersion="WIN_2000" then
    $strFolderName = "Network and Dial-up Connections"
else
    $strFolderName = "Network Connections"; Windows XP
endif
 
Select 
    Case StringInStr("0409,0809,0c09,1009,1409,1809,1c09,2009,2409,2809,2c09,3009,3409", @OSLang) ; English (United States)
       $strEnableVerb  = "En&able"
       $strDisableVerb = "Disa&ble"
 
; Add here the correct Verbs for your Operating System Language
EndSelect
 
 
;Virtual folder containing icons for the Control Panel applications. (value = 3)
Const $ssfCONTROLS = 3 
 
$ShellApp = ObjCreate("Shell.Application")
$oControlPanel = $shellApp.Namespace($ssfCONTROLS)
 
 
; Find 'Network connections' control panel item
$oNetConnections=""
 
For $FolderItem in $oControlPanel.Items
    If $FolderItem.Name = $strFolderName then
        $oNetConnections = $FolderItem.GetFolder
        Exitloop
    Endif
Next
 
      
If not IsObj($oNetConnections) Then
    MsgBox(0,"Error","Couldn't find " & $strFolderName & " folder." )
    Exit
EndIf
        
 
For $FolderItem In $oNetConnections.Items
    If StringLower($FolderItem.Name) = StringLower($oLanConnection) Then
        $oLanConnection = $FolderItem
        Exitloop
    EndIf
Next
 
If not IsObj($oLanConnection) Then
     MsgBox(0,"Error","Couldn't find " & $oLanConnection & " Item." )
     Exit
EndIf
 
$oEnableVerb=""
$oDisableVerb=""
 
For $Verb In $oLanConnection.Verbs
 If $Verb.Name = $strEnableVerb Then
   $oEnableVerb = $Verb
 EndIf
 If $Verb.Name = $strDisableVerb Then
   $oDisableVerb = $Verb
 EndIf
Next
 
If $bEnable then
 If IsObj($oEnableVerb) Then $oEnableVerb.DoIt  ; Enable network card
Endif
 
If not $bEnable then
 If IsObj($oDisableVerb) Then $oDisableVerb.DoIt; Disable network card
EndIf
 
Sleep(1000)
Edited by Melba23
Added code tags
Link to comment
Share on other sites

  • Moderators

viperpiper, did you notice the announcement at the top of this forum indicating this is not a general support forum? You will get a much better response if you request that it be moved to the appropriate forum.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

viperpiper,

Welcome to the AutoIt forum. :)

But please pay attention to where you post - the "Examples" section where you started this thread is clearly marked: "This is NOT a general support forum!". I have moved the thread for you, but would ask you to be more careful in future. ;)

And when you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...