Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to disable-Enable Local area Connection via script

1,520 views
Skip to first unread message

David S. Calef

unread,
Mar 14, 2002, 12:52:11 AM3/14/02
to
Any way to Disable and then Enable a Local Area Connection in Windows 2000
and Windows XP?

Specifically we have to disable then enable our Cable Modem every three
hours to keep it working. This is a cable specific problem that apparently
exisits on many systems.

So, can a script be created to do this. Then it can be assigned to Task
Manager to run every three hours.

David


Michael Harris

unread,
Mar 14, 2002, 11:51:00 AM3/14/02
to
Don't know how to do that but have you tried just scripting an execution of "ipconfig /renew" ???

Is this by any chance a problem that started after the @home demise? If so, the above trick worked for me (and a number of others) until the underlying problem eventually resolved itself once attbi.com got all the bugs worked out ;-)...

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--

"David S. Calef" <dca...@cfassociates.com> wrote in message news:OYrlOxxyBHA.2656@tkmsftngp03...

Alex K. Angelopoulos

unread,
Mar 14, 2002, 1:28:15 PM3/14/02
to
That's also a panacea for Win9x clients which switch between LAN and dialup connections regularly. A shortcut to ipconfig /renewall is like 2 aspirin and a bowl of chicken soup for connectivity issues on almost any connection and any Windows OS.

"Michael Harris" <mik...@mvps.org> wrote in message news:OujGah3yBHA.1796@tkmsftngp02...

David S. Calef

unread,
Mar 14, 2002, 2:26:21 PM3/14/02
to
Actually, /renew or /renewall does not work.

This cable modem is attached to a Microsoft ISA server. If I do the /renew
or anything else, the ISA server apparently can't find it, so I have to
reboot. If I put a shortcut to the Cable Modem LAN connection on my
desktop, and right-click DISABLE and then Right-Click ENABLE, the cable
modem just purrs along and so does the ISA server. So, I really need to
find a way to do this every 3 hours. It is Adelphia Cable that requires
this. Other customers (residential) are saying they have to reboot their
computer. Well, I suspect they could do what I am doing.

Thanks. I am headed for Automate 4 to see what it can do.

David

"Alex K. Angelopoulos" <alex_angelopoulos_at_hotmail_dot_com_remove__> wrote
in message news:uy3xtX4yBHA.2068@tkmsftngp05...

Michael Harris

unread,
Mar 15, 2002, 4:29:49 PM3/15/02
to
Theoretically, there _is_ a way to script this. It would involve using the Shell.Application object's Namespace method and the ParseName method of shell Folder objects on your way down to a shell FolderItem object for the lan connection. The objective (in theory) is to use the InvokeVerb method for "Disa&ble" and "En&able".

Unfortunately this is only theory on Win2000 sp2 because there is a ***BUG*** in the Shell.Application object.

I started coding up a scripted solution for this and found (rather rudely) that Folder2 interfaces where being returned by Namespace instead of Folder. That prevented access to the ParseName method (and anything else *not* on the Folder2 interface which is pretty much everything ;-)...

I thought at first that this *might* be a problem only with late bound clients like scripts. But even an early bound VB client gets the same (incorrect) Folder2 reference and generates the same 445 error with explict As Shell32.Folder variables. That would also seem to rule out any possible error in the VBScript engine as well.

Just to demonstrate the *BUG*...

=== test VBScript code ===

Const ssfCONTROLS = &h3
set shellApp = createobject("shell.application")
set obj = shellApp.Namespace(ssfCONTROLS)
msgbox obj.title ' displays "Control Panel"
msgbox typename(obj) ' displays Folder2
'
' this will throw error:
' 445 "Object doesn't support this action"
' which is essentially a "not implemented" error. ParseName is
' implemented on the Folder interface, not Folder2.
'
set obj2 = obj.ParseName("Display")

=== test VB code ===

Dim shellApp As Shell32.Shell
Dim obj As Shell32.Folder
Dim obj2 As Shell32.Folder
Const ssfCONTROLS = &H3
Set shellApp = CreateObject("shell.application")
Set obj = shellApp.Namespace(ssfCONTROLS)
MsgBox obj.Title ' displays "Control Panel"
MsgBox TypeName(obj) ' displays Folder2
'
' this will throw error:
' 445 "Object doesn't support this action"
' which is essentially a "not implemented" error. ParseName is
' implemented on the Folder interface, not Folder2.
'
Set obj2 = obj.ParseName("Display")


--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--

"David S. Calef" <dca...@cfassociates.com> wrote in message news:OxxXJ44yBHA.2456@tkmsftngp05...

David S. Calef

unread,
Mar 16, 2002, 1:00:20 AM3/16/02
to
Hey Mike:

I really do appreciate you playing around with this. This is not just a
problem I have, but apprently is a big one with some cable modem suppliers
from what I am hearing.

I did get Automate 4 to work very well. But I sure can see its
shortcomings, at least in what I know about it. I was successful in having
in record a Start | settings | Network Connections | Right Click Adelphia
Cable Modem | Disable. And then repeat the process to enable.

I tried to set it up on the Boss's Sony Vaio XP Home laptop so it would
change settings between the Office LAN and dialup for home use. Because
Windows were opening, and they did not always open exactly in the same
place, it failed miserably. So that Sucks. Guess I am lucky it works
for the LAN disable, enable because all the windows that open are rooted in
the start menu.

But anyway... thanks for taking the time. You are way beyond me as I have
never used VBScript for anything but copying files and renaming files from
within a VB program.

David


"Michael Harris" <mik...@mvps.org> wrote in message

news:ekPb4hGzBHA.2376@tkmsftngp02...

Michael Harris

unread,
Mar 25, 2002, 2:34:42 PM3/25/02
to
Ok, it's not a bug, it is apparently a "design decision" ;-)...

Per the response I got from a Microsoft Developer Support Tech Lead, ParseName is not implemented on Win2K for the Control Panel Folder object, but *is* implemented on WinXP.

The fact is that there *may* be *other* circumstances where ParseName will return "not implemented" (decimal 445 error or hex 0x800A01BD). The reality is that any given shell folder object (and maybe sub objects) may not implement all interface members. This is especially true of 3rd party shell folder extensions. My suggestion to at least document this possibility is being considered.

To be 100% robust, you should enable inline error handling and explicitly test for "not implemented" and use an alterative approach of an enumerated search of the Folder's FolderItems collection (returned by the Items() method) looking for a FolderItem.Name match.

If you need the Folder interface rather that FolderItem, use the FolderItem.GetFolder property (yes, it _is_ a property despite a method-like name;-). On the other hand, if you have a Folder interface and want its FolderItem interface, use the Folder.Self property. Note the Self was added as of Windows 2000.

So here's what I finally came up with: the script below will toggle the LAN connection back and forth between enabled and disable. The approach I took was the brute force search since that would work on both Win2K and XP...

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

==========================================================

0 new messages