Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Issues with a script

Status
Not open for further replies.

kpeterson

IS-IT--Management
Jun 7, 2005
42
0
0
CA
I have found a script at which will allow me to enable/disable a network connection.

Code:
<package>
<comment>
NICToggle.wsf
This script looks at your ‘Local Area Connection’
and enables it if disabled, disables it if enabled.
</comment>
<job>
<runtime>
<description>
Script for toggling network connection on/off
</description>

<example>
C:\>cscript ToggleNIC.wsf
</example>
</runtime>
<object id=”objShell” progid=”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

strNetConn = “Network Connections”
strConn = “Local Area Connection”

strEnable = “En&able”
strDisable = “Disa&ble”

Set objCP = objShell.Namespace(3) ‘Control Panel

Set colNetwork = Nothing
For Each clsConn in objCP.Items
If clsConn.Name = strNetConn Then
Set colNetwork = clsConn.getfolder
Exit For
End If
Next

If colNetwork is Nothing Then
WScript.Echo “Network folder not found”
WScript.Quit
End If

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

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

If clsLANConn is Nothing Then
WScript.Echo “Network Connection not found”
WScript.Quit
End If

bEnabled = True
Set objEnable = Nothing
Set objDisable = Nothing
For Each clsVerb in clsLANConn.verbs
If clsVerb.name = strEnable Then 
Set objEnable = clsVerb 
bEnabled = False
End If
If clsVerb.name = strDisable Then 
Set objDisable = clsVerb 
End If
Next

If bEnabled Then
objDisable.DoIt
Else
objEnable.DoIt
End If

‘Give the connection time to stop/start
WScript.Sleep 1000 

</script>
</job>
</package>

When I run the script i get the following error, (18, 24) Windows Script Host: The value for the attribute is not valid : progid

I Don't really know anything about vbscript and would really appreciate a little help on this. Im sure it is a has a simple solution. Thanks
 
The wsf contains non-ascii characters, maily those straight double quotes. Is it originating from some ebcdic file? You have to translate it to plain text ascii file for it to run.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top