Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I basically want to shutdown/start some services based on Network name and type I connect, so even better to run script when the network is automatically detected is it possible? Thanks.

share|improve this question

4 Answers 4

up vote 1 down vote accepted

There may be some tool out there, but you can roll your own with some work.

See this link about working with WMI events: http://trevorsullivan.net/2009/11/16/powershell-getting-started-with-wmi-events/

Basically you'd be writing a powershell script or c# program to listen for WMI events, which can be something like a dhcp lease being renewed or the connection coming online. But you'd have to do some more digging for the specific event you want if it's not a the dhcp lease event (which it sounds like it's not.) Then your script can do whatever you want when that event comes up - like starting services etc.

The link should provide you with some direction to keep looking in, or punt because it's kind of a pain.

You'd want to use some kinda of query like this in wbemtest to drill down and see which event you are interested in (like the article spells out). Then you'd do the necessary register-wmi event stuff in powershell once you're happy with your query.

SELECT * FROM __InstanceModificationEvent WITHIN 3 WHERE TargetInstance ISA 'Win32_NetworkAdapterConfiguration'
share|improve this answer
    
Thank you very much for such an brief answer, down there is also additional answer how to make it even simpler with Windows Task Scheduler which I was looking for. –  amsys Sep 30 '10 at 7:46

You can also use the Windows Task Scheduler for listening on the WMI event.

share|improve this answer
    
You are the best, don't know to which answer to put now the green check :x –  amsys Sep 30 '10 at 7:46
    
+1 - Didn't know that trick. Looks a little tricky to configure but with enough playing looks like it would be pretty cool. –  Matt Sep 30 '10 at 16:01

That sounds like the problem that the Network Location Awareness service tries to solve. I bet PowerShell could be employed to use whatever .NET plumbing exists to listen for NLA service events.

share|improve this answer

You could set up a permanent WMI event consumer, using either the CommandLineEventConsumer or ActiveScriptEventConsumer.

http://msdn.microsoft.com/en-us/library/aa384749(v=VS.85).aspx - Active Script Event Consumer

http://msdn.microsoft.com/en-us/library/aa393249(v=VS.85).aspx - Command Line Event Consumer

Cheers

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.