Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > disable NIC based on connection state

Reply
Thread Tools Display Modes

disable NIC based on connection state

 
 
Joey
Guest
Posts: n/a

 
      08-12-2009
Is there a script that will disable a nic based on the connection state?


 
Reply With Quote
 
 
 
 
Pegasus [MVP]
Guest
Posts: n/a

 
      08-13-2009

"Joey" <> wrote in message
news:%...
> Is there a script that will disable a nic based on the connection state?


Please elaborate.


 
Reply With Quote
 
Joey
Guest
Posts: n/a

 
      08-14-2009
I am creating a sysprep image for 2003 server. upon bootup, I want to run a
runonce script that will disable any nics that does not have a "connected"
state. I know how to disable it with netsh but not sure how to detect the
"state" of the nic

"Pegasus [MVP]" <> wrote in message
news:...
>
> "Joey" <> wrote in message
> news:%...
>> Is there a script that will disable a nic based on the connection state?

>
> Please elaborate.
>



 
Reply With Quote
 
Pegasus [MVP]
Guest
Posts: n/a

 
      08-14-2009
Here you go:

iEthernet = 0: iWireless = 9
aStatus = Split("Disconnected/Connecting/Connected/Disconnecting/" _
& "Hardware not present/Hardware disabled/Hardware malfunction/" _
& "Media disconnected/Authenticating/Authentication succeeded/" _
& "Authentication failed", "/")
Set oWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = oWMIService.ExecQuery( _
"SELECT * FROM Win32_NetworkAdapter",,48)
For Each oItem In colItems
If (oItem.AdapterTypeId = iEthernet _
Or oItem.AdapterTypeId = iWireless) _
And Not IsNull(oItem.NetConnectionStatus) _
Then WScript.Echo oItem.Name & ": " _
& aStatus(oItem.NetConnectionStatus)
Next

"Joey" <> wrote in message
news:%...
>I am creating a sysprep image for 2003 server. upon bootup, I want to run a
>runonce script that will disable any nics that does not have a "connected"
>state. I know how to disable it with netsh but not sure how to detect the
>"state" of the nic
>
> "Pegasus [MVP]" <> wrote in message
> news:...
>>
>> "Joey" <> wrote in message
>> news:%...
>>> Is there a script that will disable a nic based on the connection state?

>>
>> Please elaborate.
>>

>
>



 
Reply With Quote
 
Joey
Guest
Posts: n/a

 
      08-16-2009
how do I disable the nics showing as "Media disconnected"?
"Pegasus [MVP]" <> wrote in message
news:...
> Here you go:
>
> iEthernet = 0: iWireless = 9
> aStatus = Split("Disconnected/Connecting/Connected/Disconnecting/" _
> & "Hardware not present/Hardware disabled/Hardware malfunction/" _
> & "Media disconnected/Authenticating/Authentication succeeded/" _
> & "Authentication failed", "/")
> Set oWMIService = GetObject("winmgmts:\\.\root\CIMV2")
> Set colItems = oWMIService.ExecQuery( _
> "SELECT * FROM Win32_NetworkAdapter",,48)
> For Each oItem In colItems
> If (oItem.AdapterTypeId = iEthernet _
> Or oItem.AdapterTypeId = iWireless) _
> And Not IsNull(oItem.NetConnectionStatus) _
> Then WScript.Echo oItem.Name & ": " _
> & aStatus(oItem.NetConnectionStatus)
> Next
>
> "Joey" <> wrote in message
> news:%...
>>I am creating a sysprep image for 2003 server. upon bootup, I want to run
>>a runonce script that will disable any nics that does not have a
>>"connected" state. I know how to disable it with netsh but not sure how to
>>detect the "state" of the nic
>>
>> "Pegasus [MVP]" <> wrote in message
>> news:...
>>>
>>> "Joey" <> wrote in message
>>> news:%...
>>>> Is there a script that will disable a nic based on the connection
>>>> state?
>>>
>>> Please elaborate.
>>>

>>
>>

>
>



 
Reply With Quote
 
Pegasus [MVP]
Guest
Posts: n/a

 
      08-17-2009
I suppose you use the method you had in mind when you wrote "I know how to
disable it with netsh ".

"Joey" <> wrote in message
news:...
> how do I disable the nics showing as "Media disconnected"?



 
Reply With Quote
 
Joey
Guest
Posts: n/a

 
      08-17-2009
Hi

I am trying to disable the NetConnectionID when the output shows as
DISABLED. I cant see mt oget it to work with this

iEthernet = 0: iWireless = 9
aStatus = Split("Disconnected/Connecting/Connected/Disconnecting/" _
& "Hardware not present/Hardware disabled/Hardware malfunction/" _
& "Media disconnected/Authenticating/Authentication succeeded/" _
& "Authentication failed", "/")
Set oWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = oWMIService.ExecQuery( _
"SELECT * FROM Win32_NetworkAdapter",,48)
For Each oItem In colItems
If (oItem.AdapterTypeId = iEthernet _
Or oItem.AdapterTypeId = iWireless) _
And Not IsNull(oItem.NetConnectionStatus) _
Then WScript.Echo oItem.NetConnectionID & ": " _
& aStatus(oItem.NetConnectionStatus)
If (astatus(oItem.NetConnectionStatus) = "Media disconnected")
netsh interface set interface oItem.NetConnectionID DISABLED
Next

Can you point me in the right direction?

Thanks


"Pegasus [MVP]" <> wrote in message
news:...
>I suppose you use the method you had in mind when you wrote "I know how to
>disable it with netsh ".
>
> "Joey" <> wrote in message
> news:...
>> how do I disable the nics showing as "Media disconnected"?

>
>



 
Reply With Quote
 
Pegasus [MVP]
Guest
Posts: n/a

 
      08-17-2009
netsh is an .exe file. You cannot invoke it directly from a VB Script. Use
the "run" or "exec" method to invoke it. If you're not familiar with these
methods, use calc.exe as a practice program before moving on to netsh. You
should also download the helpfile script56.chm from the Microsoft site.

Alternatively (and I suggest this even though you're in a scripting and not
a batch file newsgroup), you could stick to a batch file like so:
1. Use cscript.exe to invoke the script I gave you.
2. Terminate it with wscript.quite(x) where you set x=0 if the adapter is
disconnected, x=1 if it is connected.
3. Use your batch file to check the %ErrorLevel% of cscript.exe. "0" means
the adapter is disconnected.
4. Invoke netsh according to this error level.

"Joey" <> wrote in message
news:...
> Hi
>
> I am trying to disable the NetConnectionID when the output shows as
> DISABLED. I cant see mt oget it to work with this
>
> iEthernet = 0: iWireless = 9
> aStatus = Split("Disconnected/Connecting/Connected/Disconnecting/" _
> & "Hardware not present/Hardware disabled/Hardware malfunction/" _
> & "Media disconnected/Authenticating/Authentication succeeded/" _
> & "Authentication failed", "/")
> Set oWMIService = GetObject("winmgmts:\\.\root\CIMV2")
> Set colItems = oWMIService.ExecQuery( _
> "SELECT * FROM Win32_NetworkAdapter",,48)
> For Each oItem In colItems
> If (oItem.AdapterTypeId = iEthernet _
> Or oItem.AdapterTypeId = iWireless) _
> And Not IsNull(oItem.NetConnectionStatus) _
> Then WScript.Echo oItem.NetConnectionID & ": " _
> & aStatus(oItem.NetConnectionStatus)
> If (astatus(oItem.NetConnectionStatus) = "Media disconnected")
> netsh interface set interface oItem.NetConnectionID DISABLED
> Next
>
> Can you point me in the right direction?
>
> Thanks
>
>
> "Pegasus [MVP]" <> wrote in message
> news:...
>>I suppose you use the method you had in mind when you wrote "I know how to
>>disable it with netsh ".
>>
>> "Joey" <> wrote in message
>> news:...
>>> how do I disable the nics showing as "Media disconnected"?

>>
>>

>
>



 
Reply With Quote
 
Joey
Guest
Posts: n/a

 
      08-18-2009
I am not sure how to pass the "NetConnectionID" to the batch file. any idea?

Thanks

"Pegasus [MVP]" <> wrote in message
news:...
> netsh is an .exe file. You cannot invoke it directly from a VB Script. Use
> the "run" or "exec" method to invoke it. If you're not familiar with these
> methods, use calc.exe as a practice program before moving on to netsh. You
> should also download the helpfile script56.chm from the Microsoft site.
>
> Alternatively (and I suggest this even though you're in a scripting and
> not a batch file newsgroup), you could stick to a batch file like so:
> 1. Use cscript.exe to invoke the script I gave you.
> 2. Terminate it with wscript.quite(x) where you set x=0 if the adapter is
> disconnected, x=1 if it is connected.
> 3. Use your batch file to check the %ErrorLevel% of cscript.exe. "0" means
> the adapter is disconnected.
> 4. Invoke netsh according to this error level.
>
> "Joey" <> wrote in message
> news:...
>> Hi
>>
>> I am trying to disable the NetConnectionID when the output shows as
>> DISABLED. I cant see mt oget it to work with this
>>
>> iEthernet = 0: iWireless = 9
>> aStatus = Split("Disconnected/Connecting/Connected/Disconnecting/" _
>> & "Hardware not present/Hardware disabled/Hardware malfunction/" _
>> & "Media disconnected/Authenticating/Authentication succeeded/" _
>> & "Authentication failed", "/")
>> Set oWMIService = GetObject("winmgmts:\\.\root\CIMV2")
>> Set colItems = oWMIService.ExecQuery( _
>> "SELECT * FROM Win32_NetworkAdapter",,48)
>> For Each oItem In colItems
>> If (oItem.AdapterTypeId = iEthernet _
>> Or oItem.AdapterTypeId = iWireless) _
>> And Not IsNull(oItem.NetConnectionStatus) _
>> Then WScript.Echo oItem.NetConnectionID & ": " _
>> & aStatus(oItem.NetConnectionStatus)
>> If (astatus(oItem.NetConnectionStatus) = "Media disconnected")
>> netsh interface set interface oItem.NetConnectionID DISABLED
>> Next
>>
>> Can you point me in the right direction?
>>
>> Thanks
>>
>>
>> "Pegasus [MVP]" <> wrote in message
>> news:...
>>>I suppose you use the method you had in mind when you wrote "I know how
>>>to disable it with netsh ".
>>>
>>> "Joey" <> wrote in message
>>> news:...
>>>> how do I disable the nics showing as "Media disconnected"?
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Pegasus [MVP]
Guest
Posts: n/a

 
      08-18-2009
Your question is unclear. I suggest you clarify it by posting these pieces
of info:
- The output generated by my VB Script code.
- The output generated by ipconfig.exe /all
- The input expected by netsh.exe.

"Joey" <> wrote in message
news:...
>I am not sure how to pass the "NetConnectionID" to the batch file. any
>idea?
>
> Thanks
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Invoking IISREST based on a website state Walid Scripting 0 09-07-2007 10:16 PM
ASP.NET - The state server has closed an expired TCP/IP connection dm3281 Windows Server 0 10-14-2006 06:45 PM
Disable the screensaver policy based on IP address or DHCP paramet wwc Active Directory 1 09-02-2005 05:37 PM
Need a script to disable or enable based off wireless connection being used. TC Scripting 0 06-10-2005 01:38 AM
Disable Save State on menu Cliff Benoist Virtual PC 2 02-03-2004 11:08 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59