Solved

Local/Remote disabling/enabling lan connection

Posted on 2003-10-26
4
358 Views
Last Modified: 2010-04-13
Hi,

I use a W2Kpro pc to share i'net with 2 other pc's, also w2kpro. Now I have a problem with one of the lan connections, after booting sometimes the connection doesn't work. Sometimes it does, sometimes it doesn't.... when I get no response on a ping on that connection, I have to open the connection properties, choose disable, and after that just enable it again. Then it always works. I think it is a problem on the client pc, although I wouldn't know what. Or something with the utp cable.. who knows... but what I really want to now at this moment:
Can I, locally or remote, disable/enable a lan connection with a dosprompt command? So I could use a batch for this? I've tried netsh, but no luck with that.

Any help greatly appreciated
0
Comment
Question by:mrjoe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
NahumK earned 125 total points
ID: 9623185
taken from http://www.mcpmag.com/columns/mcsescripting/

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

 
0
 

Author Comment

by:mrjoe
ID: 9626060
That looks very promissing, although it gives an error with me. I must warn you, this is my first experience with windows scripting!

The warning is in dutch here, translated it would be: "The value for the attribute is invalid : progid."

On this line: <object id=”objShell” progid=”Shell.Application”/>

Is this something I need to enable/install first?

thanks in advance
0
 
LVL 1

Expert Comment

by:NahumK
ID: 9626693
open the script file in a dos editor. what you'll probably see is some wierd characters where characters like '," and / should be. (notepad screwed up conversion from unicode to ascii?)
replace the weird characters with the characters that should be there and the script will run.
0
 

Author Comment

by:mrjoe
ID: 9627648
Indeed, didn't thought about opening the file in a dos editor.. I still had to change the “En&able” and “Disa&ble” to their dutch equivalents, but it works now. I feel great about my first step in win scripting =)

Great help, tnx.
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

630 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