ciii Posted December 27, 2012 Report Share Posted December 27, 2012 I want to write program wich can enable/disable local or global network on one or more windows pc's. With what I should start and if it is possible? Quote Link to comment Share on other sites More sharing options...
AlanHo Posted December 27, 2012 Report Share Posted December 27, 2012 Copy this and pretend you wrote it... <package><comment>NICToggle.wsfThis 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 offOption ExplicitDim objCP, objEnable, objDisable, colNetworkDim clsConn, clsLANConn, clsVerbDim strNetConn, strConn, strEnable, strDisableDim bEnabled, bDisabledstrNetConn = “Network Connections”strConn = “Local Area Connection”strEnable = “En&able”strDisable = “Disa&ble”Set objCP = objShell.Namespace(3) ‘Control PanelSet colNetwork = NothingFor Each clsConn in objCP.ItemsIf clsConn.Name = strNetConn ThenSet colNetwork = clsConn.getfolderExit ForEnd IfNextIf colNetwork is Nothing ThenWScript.Echo “Network folder not found”WScript.QuitEnd IfSet clsLANConn = NothingFor Each clsConn in colNetwork.Items‘In case the LAN is named “connection 2”, etc.If Instr(LCase(clsConn.name),LCase(strConn)) ThenSet clsLANConn = clsConnExit ForEnd IfNextIf clsLANConn is Nothing ThenWScript.Echo “Network Connection not found”WScript.QuitEnd IfbEnabled = TrueSet objEnable = NothingSet objDisable = NothingFor Each clsVerb in clsLANConn.verbsIf clsVerb.name = strEnable ThenSet objEnable = clsVerbbEnabled = FalseEnd IfIf clsVerb.name = strDisable ThenSet objDisable = clsVerbEnd IfNextIf bEnabled ThenobjDisable.DoItElseobjEnable.DoItEnd If‘Give the connection time to stop/startWScript.Sleep 1000</script></job></package>Digging Into the ScriptThis 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. Quote Link to comment Share on other sites More sharing options...
ciii Posted December 27, 2012 Author Report Share Posted December 27, 2012 Copy this and pretend you wrote it... <package><comment>NICToggle.wsfThis 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 offOption ExplicitDim objCP, objEnable, objDisable, colNetworkDim clsConn, clsLANConn, clsVerbDim strNetConn, strConn, strEnable, strDisableDim bEnabled, bDisabledstrNetConn = “Network Connections”strConn = “Local Area Connection”strEnable = “En&able”strDisable = “Disa&ble”Set objCP = objShell.Namespace(3) ‘Control PanelSet colNetwork = NothingFor Each clsConn in objCP.ItemsIf clsConn.Name = strNetConn ThenSet colNetwork = clsConn.getfolderExit ForEnd IfNextIf colNetwork is Nothing ThenWScript.Echo “Network folder not found”WScript.QuitEnd IfSet clsLANConn = NothingFor Each clsConn in colNetwork.Items‘In case the LAN is named “connection 2”, etc.If Instr(LCase(clsConn.name),LCase(strConn)) ThenSet clsLANConn = clsConnExit ForEnd IfNextIf clsLANConn is Nothing ThenWScript.Echo “Network Connection not found”WScript.QuitEnd IfbEnabled = TrueSet objEnable = NothingSet objDisable = NothingFor Each clsVerb in clsLANConn.verbsIf clsVerb.name = strEnable ThenSet objEnable = clsVerbbEnabled = FalseEnd IfIf clsVerb.name = strDisable ThenSet objDisable = clsVerbEnd IfNextIf bEnabled ThenobjDisable.DoItElseobjEnable.DoItEnd If‘Give the connection time to stop/startWScript.Sleep 1000</script></job></package>Digging Into the ScriptThis 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? Quote Link to comment Share on other sites More sharing options...
AlanHo Posted December 27, 2012 Report Share Posted December 27, 2012 it is best you work it out for yourself - otherwise you will not learn anything.There are plenty of clues in the script. Quote Link to comment Share on other sites More sharing options...
ciii Posted December 28, 2012 Author Report Share Posted December 28, 2012 it is best you work it out for yourself - otherwise you will not learn anything.There are plenty of clues in the script.Shows that in line 17 is error: The value for the attribute is not valid: progid Quote Link to comment Share on other sites More sharing options...
MANEMAN Posted December 28, 2012 Report Share Posted December 28, 2012 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 INFORMATIONWF Is still accepting nominations for the forum genius of 2012 up until 31st December. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.