For Programmers: Free Programming Magazines  


Home > Archive > Windows Server Scripting > February 2005 > Need Script for Disabling, Enabling Network Card









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Need Script for Disabling, Enabling Network Card
googlemike@hotpop.com

2005-02-16, 3:55 pm

We're having a strange intermittent issue where users can't reach a few
of our multi-homed W2K servers, and only one at a time, almost
randomly, one server a day. (It's in an AD domain and we do have a
local DNS and WINS and they seem to be operating properly.) We found if
we disable and re-enable the second network card, the users can connect
again for a little while. We'd like to now switch this to a script. We
can't do it in batch file that I'm aware of, so we need to switch to
VBS and may need to use Windows Management Interface API to get it
going. Has anyone done this before?

Microsoft has already tried to work with us to check out the DNS/WINS
configuration and tried to identify why our master browsing was kind of
wacky. They suggested a change where we stop computer browser service
on all multi-homed servers that are not the WINS/DNS/DC servers, so we
did that, but it did not help.

It's only a matter of time, anyway, before we switch our file/print
sharing to Linux. Our new app servers are already Linux and I boot up
on Linux now as admin. The script we need is just an interim measure.

NOTE: If this were Linux, we'd have a Bash script in a jiffy that would
use ifdown and ifup on eth0 or eth1 to disable and re-enable this --
but then again, Linux wouldn't have this intermittent multihoming issue
in the first place. But that's my two cents.

MikeVa [MSFT]

2005-02-16, 3:55 pm

NETSH.EXE can do this via a batch file.

netsh interface set interface name = "Local Area Connection 2" admin =
DISABLED

You need to be able to identify the NIC by the friendly name that is
displayed in "Network Connections"

--
MikeVa [MSFT]

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of any included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
--
Please do not send e-mail directly to this alias.
This alias is for newsgroup purposes only.
--
<googlemike@hotpop.com> wrote in message
news:1108574122.823361.236460@f14g2000cwb.googlegroups.com...
> We're having a strange intermittent issue where users can't reach a few
> of our multi-homed W2K servers, and only one at a time, almost
> randomly, one server a day. (It's in an AD domain and we do have a
> local DNS and WINS and they seem to be operating properly.) We found if
> we disable and re-enable the second network card, the users can connect
> again for a little while. We'd like to now switch this to a script. We
> can't do it in batch file that I'm aware of, so we need to switch to
> VBS and may need to use Windows Management Interface API to get it
> going. Has anyone done this before?
>
> Microsoft has already tried to work with us to check out the DNS/WINS
> configuration and tried to identify why our master browsing was kind of
> wacky. They suggested a change where we stop computer browser service
> on all multi-homed servers that are not the WINS/DNS/DC servers, so we
> did that, but it did not help.
>
> It's only a matter of time, anyway, before we switch our file/print
> sharing to Linux. Our new app servers are already Linux and I boot up
> on Linux now as admin. The script we need is just an interim measure.
>
> NOTE: If this were Linux, we'd have a Bash script in a jiffy that would
> use ifdown and ifup on eth0 or eth1 to disable and re-enable this --
> but then again, Linux wouldn't have this intermittent multihoming issue
> in the first place. But that's my two cents.
>



googlemike@hotpop.com

2005-02-19, 3:55 am

This doesn't seem to work on Windows 2000 Server when we tried this.
Would seem to work well, though by what you describe, however. We
certainly had our hopes up here.

We tried it in various ways for a NIC connection we have named "Backup"
instead of "Local Area Connection 2". These were the ways:

netsh interface set interface name="Backup" admin=DISABLED
netsh int set int Backup DISABLED
netsh int set int Backup admin=DISABLED
netsh interface set interface name=Backup admin=DISABLED
netsh interface set interface Backup admin=DISABLED
netsh interface set interface name = "Backup" admin = DISABLED
netsh interface set interface name="Backup" admin=DISABLED
netsh interface set interface Backup DISABLED
netsh interface set interface Backup admin=DISABLED

....and unfortunately none of these worked. When I did some digging, I
found that this won't work with static IPs, on DHCP IPs. Second, it
appears to not be a functioning API on W2K and doesn't work until one
goes to XP or W2K3.

I tried the WMI route in VBScript, which, I must say is about the
craziest API I've ever laid my eyes on since the days of Win32 API from
VB, and this didn't work. In fact, MS also admits on the WMI API
website that the WMI route has no provider for disabling the NIC and
that this must be done manually through the GUI!

So, it's a no go.

I also tried seeing if registry changes occur by hacking around in the
registry under GUIDs for the NICs and I didn't find a change I could
make that would trigger this properly.

So you can't get there from here. Gosh, thanks, Microsoft!

In Linux, it's a no brainer:

#!/bin/bash
/sbin/ifdown eth1
/sbin/ifup eth1



MikeVa [MSFT] wrote:
> NETSH.EXE can do this via a batch file.
>
> netsh interface set interface name = "Local Area Connection 2" admin

=
> DISABLED
>
> You need to be able to identify the NIC by the friendly name that is
> displayed in "Network Connections"
>
> --
> MikeVa [MSFT]


Torgeir Bakken \(MVP\)

2005-02-22, 8:55 am

googlemike@hotpop.com wrote:

> This doesn't seem to work on Windows 2000 Server when we tried this.
> Would seem to work well, though by what you describe, however. We
> certainly had our hopes up here.

Hi

With Shell.Application/VBScript (Win2k and WinXP):

From: Michael Harris
Subject: Re: How to disable-Enable Local area Connection via script
Newsgroups: microsoft.public.scripting.vbscript
Date: 2002-03-25 11:36:10 PST
http://groups.google.co.uk/groups?t...8%40tkmsftngp05


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/sc...er/default.mspx
googlemike@hotpop.com

2005-02-22, 3:55 pm

Your first post from Michael Harris just might work. I'll test
tomorrow. Today I'm out sick with a cold and was catching up on
newsgroups and email.

Yesterday I called Microsoft because I didn't get this post until
today. They had a tool called devcon.exe from the Windows 2000 Server
Support Tools. It permitted me to disable or enable any device I can
see in Device Manager. This worked effectively although the way you
grab a device is really, really weird. It's also slightly buggy because
you could end up disabling more than one device if you're not careful.
(That's what happened the first time I ran it!)

The way you run it is:

devcon status @pci

This displayed all the PCI devices in the PC and their weird names.
Next, you then find the name in question and try to do a status just on
that. (Search Microsoft KB for devcon.exe usage because this is way too
lengthy to describe here.)

Once you are able to run just a status on just the device in question,
then you have achieved the proper syntax. Now you can switch "status"
with "enable" or "disable".

When I did this, I was delighted to see that it worked and the GUI was
updated immediately with a greyed out icon as if I right-clicked and
went Enable or Disable.

Now all I need to do is have this command be triggered whenever I
receive a particular event on the SQL Server in the event log. You see,
what's happening is that we have a SQL Server with 2 network cards in
it. One network card goes to the LAN. The other card goes to an
isolated fiber hub and is used by the tape backup server to back the
server up without running over the LAN card. The problem we're
experiencing is that we get master browser and computer name issues for
no apparent reason on multiple servers (SQL and file share servers) if
they are multihomed like this. Microsoft told us to turn off the
Computer Browser service on each multihomed server except the domain
controllers and then reboot the servers and do "nbtstat -R". When we
did this, it didn't help. The end users experience the problem because
both network cards just freeze up with nothing identifiable in the
event logs except related symptoms like MS SQL Server complaining with
event 17060. The way we fix it is by bouncing the backup network card
on the afflicted server and now both the LAN and Backup NICs function
properly. Since Microsoft couldn't figure the problem out, we gave up
on that strategy and just asked them to identify for us a way to
disable/enable the NICs from script, which they did.

I believe there's a WMI script I can use from VBScript to dump out an
event log and filter for an event. Perhaps I can use Perfmon to trap it
and fire a devcon.exe task.

My boss warns me, however, that if I do this while a backup NIC is
being used for backing up the database, he fears it might corrupt the
database. So, that presents another problem -- I have to run this
command when I receive a 17060 error from SQL Server in the event log,
but then ensure that the backups aren't running against it. We do
hourly transaction backups and daily full backups on the SQL Servers.

But wait, you might say -- "I thought you said that both NICs freeze
up? How can the backups be running?" Well, I don't know -- there just
might be a slim case of them running and the LAN NIC is not
functioning. It's a slim possibility and a risk I need to account for.

In general, I just don't think Microsoft W2K Server can handle
multihoming like Linux and Unix can. The scripts also suck compared to
Linux and Unix. With W2K, you end up with a lot of "can't get there
from here" situations.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com