**Disconnec Wireless Networking**

Hi

This is very important that i know this...

I have created a vbscript that detects the NIC's IP Address and if the IP address is withing the conditions - it stops the following services:

Smart Card Service
Wireless Zone Configuration Service

Under the group policy set - user's cannot start services - so they cannot connect into a wireless network.

PROBLEM: When the user logs into the network with a network cable its fine, my script works.

But...

If they take out the network cable, and re-insert it? what happens - it assigns a DHCP address -

or if they log on locally - then they insert the network cable - it picks up an IP and wireless is available...

** I want to know either the following...

what triggers or whats the event that occurs when a network cable is inserted? how can i stop this? how can i possible trigger a VBScript to run when a network cable is inserted? is this possible? i know that there are apps for this (i.e. IPSwicther), but i want to avoid 3rd party apps...

I want to know whether it is possible to run my script when the network cable is inserted or removed?
Can anyone help?

Im very desperate!!!

[1235 byte] By [alpstar01] at [2008-2-5]
# 1
You might want to check the System.Net.NetworkInformation namespace.

From the documentation

The NetworkChange class provides address change notification by raising NetworkAddressChanged events. An interface address can change for many reasons, such as a disconnected network cable, moving out of range of a wireless Local Area Network, or hardware failure.

To receive notification, you must identify your application's event handlers, which are one or more methods that perform your application-specific tasks each time the event is raised. To have a NetworkChange object call your event-handling methods when a NetworkAddressChanged event occurs, you must associate the methods with a NetworkAddressChangedEventHandler delegate, and add this delegate to the event.
It has 2 events
Name Description
NetworkAddressChanged Occurs when the IP address of a network interface changes.
NetworkAvailabilityChanged Occurs when the availability of the network changes.

Malar at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 2

Malar - thank you kindly - you have recommended a very good solution to me.

One question though - should i implement this in my logon script?

or should i have the logon script point to this file at end-of-file?

how do you think i should approach this?

i have a logon script that works fine, but how can i get a script to always run in the background?

Please help...

alpstar01 at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 3
Hi Malar.. is there is a similar way to connect/ disconnect wireless from Pocket PC, using .NET compact framework?
Krishnareddym at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 4
You can make it as a service like IIS that is automatically started when the computer boots.. It is very easy to create a service with .Net version 2.0.. I am not sure if those APIs are supported in 1.1.. Unfortunately I cannot access the code now.. I'll can help you with a simple code to create a service tomorrow..
Malar at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 5

Are you using .Net 2.0.. I'll check with the compact framework people and get back to you tomorrow..

Malar at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 6

Create a class that extends from servicebase.. MSDN has an example of a simple service that extends from servicebase..

A sample installer code.. Compile both to a exe. you can install the exe using installutil from sdk tools
[RunInstaller(true)]
public class CServiceInstaller : Installer
{

private ServiceProcessInstaller MyServiceProcessInstaller;
private ServiceInstaller MyServiceInstaller;

public CServiceInstaller()
{
MyServiceProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller();
MyServiceInstaller = new System.ServiceProcess.ServiceInstaller();
//TODO:1 Change the account in which the service runs as desired
MyServiceProcessInstaller.Account = System.ServiceProcess.ServiceAccount.NetworkService;
//TODO:2 Give Descriptions of your service
MyServiceInstaller.Description = "NCL Test Service";
MyServiceInstaller.DisplayName = "NCLTestSampleService";
MyServiceInstaller.ServiceName = "NCLTestSampleService";
this.Installers.AddRange(new System.Configuration.Install.Installer[] {
MyServiceProcessInstaller,MyServiceInstaller});

}
}

From MSDN..

The ServiceInstaller constructor sets the StartType property to ServiceStartMode.Manual to specify that a user start the service. You can reset the property to ServiceStartMode.Automatic to specify that the service start when the computer reboots.

The ServiceInstaller constructor sets the StartType property to ServiceStartMode.Manual to specify that a user start the service. You can reset the property to ServiceStartMode.Automatic to specify that the service start when the computer reboots.


Malar

Malar at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 7

The IPHLPAPI.dll has a few functions like NotifyAddrChange to which you can do a pinvoke. But it works only for ipv4 and not for ipv6. You might want to be careful if you are using appdomains and want to cancel the notifications...

Another easy way of doing the same will be to use sockets and pinvoke to WSAIoctl with SIO_ADDRESS_LIST_CHANGE option..

Malar at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...

.NET Development

Site Classified