Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Disable Local Area Connection
#1
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?
#2
I have a macro that disables/enables my LAN when it stops working.

Macro
Code:
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.Select(2)
,a=acc("Disable this network device" "PUSHBUTTON" h "DirectUIHWND" "" 0x1001 0 0 "" 10)
,a.DoDefaultAction
,
,;now manually close UAC consent
,
,5
,wait 30 WA h ;;waiting until UAC consent closed
,5
,
,a=acc("Diagnose this connection" "PUSHBUTTON" h "DirectUIHWND" "" 0x1001)
,a.DoDefaultAction
,
,h2=wait(0 WV win("Windows Network Diagnostics" "#32770"))
,a=acc("Enable the network adapter *" "PUSHBUTTON" h2 "Button" "" 0x1001 0 0 "" 10)
,a.DoDefaultAction
,
,;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)
,a.Select(2)
,men 29201 win("Network Connections" "ExploreWClass") ;;Disable
,5
,men 29200 win("Network Connections" "ExploreWClass") ;;Enable
,
,;now wait a while and close 'Network Connections' window
#3
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
#4
if dir("\\computer1\folder1" 1)

But this is slow when unavailable, maybe there is a faster way.
#5
maybe the vbs code from http://groups.google.com/group/microsof ... 1141c6c93e could be used.
i am updating my virtual win7 x64 machine for having both english and german system language.

Macro ToggleLanConnection
Code:
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 folderitem.name  = "Network and Dial-up Connections" then
;;;;;set oNetConnections = folderitem.getfolder: exit for
;;;end if
;next
;
;if oNetConnections is nothing then
;;;msgbox "Couldn't find 'Network and Dial-up Connections' folder"
;;;wscript.quit
;end if
;
;set oLanConnection = nothing
;for each folderitem in oNetConnections.items
;;;if lcase(folderitem.name)  = lcase(sConnectionName) then
;;;;;set oLanConnection = folderitem: exit for
;;;end if
;next
;
;if oLanConnection is nothing then
;;;msgbox "Couldn't find '" & sConnectionName & "' item"
;;;wscript.quit
;end if
;
;bEnabled = true
;set oEnableVerb = nothing
;set oDisableVerb = nothing
;s = "Verbs: " & vbcrlf
;for each verb in oLanConnection.verbs
;;;s = s & vbcrlf & verb.name
;;;if verb.name = sEnableVerb then
;;;;;set oEnableVerb = verb  
;;;;;bEnabled = false
;;;end if
;;;if verb.name = sDisableVerb then
;;;;;set oDisableVerb = verb  
;;;end if
;next
;
;'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
;;;oDisableVerb.DoIt
;else
;'  oLanConnection.invokeverb sEnableVerb
;;;oEnableVerb.DoIt
;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"
folderitem.name = "Network and Dial-up Connections"
pi
#6
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.
#7
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)