VBScript runtime error: Object required

Posted on 2006-04-17
Last Modified: 2013-12-25
On line 75 Char 2,  I receive an error on the code below Microsoft VBScript runtime error: Object required. It's referring either to "objDisable.DoIt" or "objEnable.DoIt" . Can some one help me ? I know I must be missing something easy but I just can't find it.


The code is attempting to toggle my wireless NIC on or off without having to use Device Manager.

Code Below

NICToggle.wsf This script looks at your ‘Local Area Connection’
and enables it if disabled, disables it if enabled.
Script for toggling network connection on/off

<example> C:\>cscript ToggleNIC.wsf
<object id = "objShell" progid = "Shell.Application"/>
set objShell=CreateObject("shell.application")
<script language = "VBScript">
'Toggle NIC on or off
Option Explicit
Dim objCP, objEnable, objDisable, colNetwork
Dim clsConn, clsLANConn, clsVerb
Dim strNetConn, strConn, strEnable, strDisable
Dim bEnabled, bDisabled

strConn = "Local Area Connection"
'strEnable = "En&able" strEnable = "&Aktivieren"
'strDisable = "Disa&ble" strDisable = "&Deaktivieren"
Set colNetwork = Nothing
Set colNetwork = objShell.Namespace(NETWORK_CONNECTIONS)

' Network Connections (independent of country/language)
If colNetwork is Nothing Then
WScript.Echo "Network folder not found"
End If

Set clsLANConn = Nothing
For Each clsConn in colNetwork.Items
' In case the LAN is named “connection 2”, etc.

If Instr(LCase(,LCase(strConn)) Then
Set clsLANConn = clsConn
Exit For
End If

'WScript.Echo clsLANConn

If clsLANConn is Nothing Then
WScript.Echo "Network Connection not found"
End If

bEnabled = True
Set objEnable = Nothing
Set objDisable = Nothing
For Each clsVerb in clsLANConn.verbs  


If = strEnable Then
Set objEnable = clsVerb
bEnabled = False
End If

If = strDisable Then
Set objDisable = clsVerb
bEnabled = True
End If

If bEnabled Then
WScript.Echo clsLANConn & " Disabled"
WScript.Echo clsLANConn & " Activated"
End If

'Give the connection time to stop/start
WScript.Sleep 1000
Question by:wtm
    1 Comment
    LVL 52

    Accepted Solution

    Well, strEnable and strDisable are both commented out in your code. So, during your loop odds are that objEnable and objDisable never get set to anything.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now