?
Solved

Disable Wireless using a process triggered by an event. (VBScript / WMI)

Posted on 2007-10-16
3
Medium Priority
?
2,125 Views
Last Modified: 2013-11-09
I am trying to develope a script that will run as a service and be triggered by an event. I have a VBScripts called - NetworkConnectionEvent

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\wmi")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery("Select * from MSNdis_StatusMediaConnect")
Do While True
    Set strLatestEvent = colMonitoredEvents.NextEvent
    'msgbox "New Connection Found"
    CheckNetworkStatus()
Loop
Function CheckNetworkStatus()
  blnOnTreasuryNetwork = False
  Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
  Set colConfig = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration Where DNSDomain = 'olympus.treasury.gov'",,48)
  For Each objItem in colConfig
    blnOnTreasuryNetwork = True         
    Exit For
  Next
  Set colAdapters = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter where ProductName like '%Wireless%'",,48)
  For Each objAdapter in colAdapters
    If blnOnTreasuryNetwork Then
      'Disable Wireless            
      objAdapter.disable
    Else
      'Enable Wireless
      Call objAdapter.Enable()
    End if
  Next
End Function

The problem I am getting is the I get an error referring to this line 'objAdapter.disable'. I know it is an object I can use, and I have double-checked the syntax.

Alternatively - If you can think of a better, neater way to capture and event triggered by a wireless card being plugged in/turned on, then I'm happy to hear it. Basically I need to be able to disable the wireless service, regardless of make/model/type whenever the physical NIC gets a DNSDomain name that meets my criteria. unfortunately the only way I can think of doing this is to have something monitoring this, otherwise there would be times/occurrences where wireless and nic connectivity could run together.
0
Comment
Question by:tonysummers
  • 2
3 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 total points
ID: 20090349
Hi, from here: http://www.microsoft.com/technet/technetmag/issues/2006/11/HeyScriptingGuy/default.aspx

"A question we hear frequently is "How do I enable and disable my network adapters through a script?" Well, we won't hold you in suspense. We'll tell you right now that you can't. At least not until you're running Windows Vista". In Windows Vista two new methods have been added to the Win32_NetworkAdapter class: Enable and Disable."

So, are you using Windows Vista?

Regards,

Rob.
0
 

Author Comment

by:tonysummers
ID: 20090808
No - we are running XP SP2.. with 140+ business unit applications I think we'll be on XP for sometime.

Thanks for you response none the less.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 20090823
Sorry to hear that.  I don't think we'll get to Vista any time soon either!

Regards.

Rob.
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

This subject  of securing wireless devices conjures up visions of your PC or mobile phone connecting to the Internet through some hotspot at Starbucks. But it is so much more than that. Let’s look at the facts: devices#sthash.eoFY7dic.
In the modern office, employees tend to move around the workplace a lot more freely. Conferences, collaborative groups, flexible seating and working from home require a new level of mobility. Technology has not only changed the behavior and the expe…
This Micro Tutorial will show you how to maximize your wireless card to its maximum capability. This will be demonstrated using Intel(R) Centrino(R) Wireless-N 2230 wireless card on Windows 8 operating system.
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…

862 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