Jump to content

enable/disable


ciii
 Share

Recommended Posts

Copy this and pretend you wrote it... :devil:

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

Digging Into the Script

This script uses the Shell object to gain access to the Network Connections folder and, subsequently, the network connection itself. It then toggles the connection on and off by using “verb” methods to invoke actions from the menu. One caveat: Since it uses the Shell object, it relies on standard naming conventions. The Windows XP control panel item is called Network Connections. Win2K calls it Network and Dial-up Connections. The script doesn’t work at all on NT 4.0 or Win 9x, because the Network applet doesn’t use the same folder-based approach to managing connections. Moreover, the individual connection will often be appended with a number such as 2 or 3.

Link to comment
Share on other sites

Copy this and pretend you wrote it... :devil:

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

Digging Into the Script

This script uses the Shell object to gain access to the Network Connections folder and, subsequently, the network connection itself. It then toggles the connection on and off by using “verb” methods to invoke actions from the menu. One caveat: Since it uses the Shell object, it relies on standard naming conventions. The Windows XP control panel item is called Network Connections. Win2K calls it Network and Dial-up Connections. The script doesn’t work at all on NT 4.0 or Win 9x, because the Network applet doesn’t use the same folder-based approach to managing connections. Moreover, the individual connection will often be appended with a number such as 2 or 3.

What is that? Where I have to copy it?

Link to comment
Share on other sites

I want to write program w'h'ich can enable/disable local or global network on one or more windows pc's.

That's good. we could use a few good people around here who can write programs. We get so many who say "I want to write a program" but are complete time wasters who it turns out wouldn't recognise a program if they saw one. - Can you believe that ? :lol:

With what I should start

You could start with something similar to the script that AlanHo has posted for you, change a few things, and claim you wrote it, or just use it as it is. Let us take a look to see if does what you want shall we ?

" This script looks at your ‘Local Area Connection’

and enables it if disabled, disables it if enabled."

Wow ! Just - Wow ! That is exactly what you required, and yes it is possible. This is going to save you a lot of time isn't it ?

What is that?

Say what ? - "That" is what we have just been talking about. - Oh, I see you are having a little special programmers joke like you programmers choose to do dahling. :)

Just for the people who haven't got your talents though, we will have a look at the end of that script shall we ? - Yes we shall.

"This script uses the Shell object to gain access to the Network Connections folder and, subsequently, the network connection itself. It then toggles the connection on and off by using “verb” methods to invoke actions from the menu. One caveat: Since it uses the Shell object, it relies on standard naming conventions. The Windows XP control panel item is called Network Connections. Win2K calls it Network and Dial-up Connections. The script doesn’t work at all on NT 4.0 or Win 9x, because the Network applet doesn’t use the same folder-based approach to managing connections. Moreover, the individual connection will often be appended with a number such as 2 or 3. "

Where I have to copy it?

Yes of course you can deary, it's in public domain, no copyright stuff or anything like that involved. Bless your sweet heart for asking though. Can you explain for us in what scenario you will be using this program so that other genius types could also implement it ?

PUBLIC INFORMATION

WF Is still accepting nominations for the forum genius of 2012 up until 31st December.

GENIUSTYPE_zpse2f3c5a9.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy