Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Disable Local Area Connection
I have WIN XP and I would like to build a macro that will disable my Local Area Connection. Does anyone know how I can do this?
I have a macro that disables/enables my LAN when it stops working.

Copy      Help
;Repairs the problem when net cannot send to XP.
;Particularly, disables/enables the network connection.
;Usually you'll need to run this macro only on Vista, but may also have to run on XP.

int h h2
Acc a

if _winnt=6 ;;Vista
,run "$49$" "" "" "" 0x800 win("Network Connections" "CabinetWClass") h ;;Network Connections
,a=acc("Local Area Connection 2" "LISTITEM" h "SysListView32" "" 0x1001 0 0 "" 10)
,a=acc("Disable this network device" "PUSHBUTTON" h "DirectUIHWND" "" 0x1001 0 0 "" 10)
,;now manually close UAC consent
,wait 30 WA h ;;waiting until UAC consent closed
,a=acc("Diagnose this connection" "PUSHBUTTON" h "DirectUIHWND" "" 0x1001)
,h2=wait(0 WV win("Windows Network Diagnostics" "#32770"))
,a=acc("Enable the network adapter *" "PUSHBUTTON" h2 "Button" "" 0x1001 0 0 "" 10)
,;now manually close UAC consent and wait a while
,;then close 'Network Connections' window

else ;;XP
,run "$3$ 1E00718000000000000000000000C7AC07700232D111AAD200805FC1270E" "" "" "" 0x800 win("Network Connections" "ExploreWClass") h ;;Network Connections
,a=acc("Local Area Connection" "LISTITEM" h "SysListView32" "" 0x1001 0 0 "" 10)
,act child(a)
,men 29201 win("Network Connections" "ExploreWClass") ;;Disable
,men 29200 win("Network Connections" "ExploreWClass") ;;Enable
,;now wait a while and close 'Network Connections' window
Sad I have a routine to use "net use" command in windows XP,
in the black console windows, I type "net use \\computer1\folder1 password /USER:username" to do a LAN connection.
Sometimes the LAN is not available, and the connection fails.

Can I use Quick Macros command to check whether the "\\computer1\folder1" is on line or not ?
1) if it is on line, I use QM function to connect the LAN.
2) if not on line, the QM message show LAN is not available.
Thanks All to help answer this question Smile
if dir("\\computer1\folder1" 1)

But this is slow when unavailable, maybe there is a faster way.
maybe the vbs code from ... 1141c6c93e could be used.
i am updating my virtual win7 x64 machine for having both english and german system language.

Macro ToggleLanConnection
Copy      Help
lpstr ToggleLanConnection.vbs=
;Const ssfCONTROLS = 3
;sConnectionName = "Local Area Connection"
;sEnableVerb = "En&able"
;sDisableVerb = "Disa&ble"
;set shellApp = createobject("shell.application")
;set oControlPanel = shellApp.Namespace(ssfCONTROLS)
;set oNetConnections = nothing
;for each folderitem in oControlPanel.items
;;;if  = "Network and Dial-up Connections" then
;;;;;set oNetConnections = folderitem.getfolder: exit for
;;;end if
;if oNetConnections is nothing then
;;;msgbox "Couldn't find 'Network and Dial-up Connections' folder"
;end if
;set oLanConnection = nothing
;for each folderitem in oNetConnections.items
;;;if lcase(  = lcase(sConnectionName) then
;;;;;set oLanConnection = folderitem: exit for
;;;end if
;if oLanConnection is nothing then
;;;msgbox "Couldn't find '" & sConnectionName & "' item"
;end if
;bEnabled = true
;set oEnableVerb = nothing
;set oDisableVerb = nothing
;s = "Verbs: " & vbcrlf
;for each verb in oLanConnection.verbs
;;;s = s & vbcrlf &
;;;if = sEnableVerb then
;;;;;set oEnableVerb = verb  
;;;;;bEnabled = false
;;;end if
;;;if = sDisableVerb then
;;;;;set oDisableVerb = verb  
;;;end if
;'debugging displays left just in case...
;'msgbox s ': wscript.quit
;'msgbox "Enabled: " & bEnabled ': wscript.quit
;'not sure why, but invokeverb always seemed to work
;'for enable but not disable.  
;'saving a reference to the appropriate verb object
;'and calling the DoIt method always seems to work.
;if bEnabled then
;'  oLanConnection.invokeverb sDisableVerb
;'  oLanConnection.invokeverb sEnableVerb
;end if
;'adjust the sleep duration below as needed...
;'if you let the oLanConnection go out of scope
;'and be destroyed too soon, the action of the verb
;'may not take...
;wscript.sleep 1000
VbsExec ToggleLanConnection.vbs

those string variables are important:
sConnectionName = "Local Area Connection"
sEnableVerb = "En&able"
sDisableVerb = "Disa&ble" = "Network and Dial-up Connections"
for me working code would be helpful too. i very use remote desktop from my old notebook to my fast workstation.
but sometimes after notebook reboot the connection is slow, so after a lot of testing my current solution is to have
a desktop icon linking to the connection where i right click and disconnect. then i wait until the connection tray icon changes to disconnected
and then again right click and enable connection.

but in the end of the day it would be clever to find the primary problem what is causing the problem.
i think it has something to to with using automatic dns settings.
I wonder whether there exists another way to get a LAN's status (I am interested in TAP-Win32 Adapter) and then disable/enable it.

Many thanks.

Forum Jump:

Users browsing this thread: 1 Guest(s)