1

I would like to create an event based scheduled task in Windows 7 that starts a program (VirtualRouter) when a specific network connection via LAN is established. I tried use a Windows/NetworkProfile 10000 trigger, but it makes a loop because VirtualRouter creates it's own network connection.

Cœur
  • 37,241
  • 25
  • 195
  • 267
CamilloS
  • 23
  • 4
  • Is it acceptable for you to use a script for that? This would open several possibilities like checking which network the pc connected to within the script, or just making sure the script is only run once. – Syberdoor Dec 20 '14 at 22:21
  • Sure :) The end justifies the means ;) – CamilloS Dec 22 '14 at 12:35

1 Answers1

1

Since you said using a script is ok, the easiest way to accomplish this is probably a simple one liner in Powershell like this example:

if (! (ps | ? {$_.Path -eq "C:\Windows\system32\notepad.exe"})) {& "C:\Windows\system32\notepad.exe"}

This would just Launch your program whenever it is not already running. If you trigger this with the 10000 event on network connection every time it will still only start your program once.

I chose Powershell because it is included in windows and it's a nice one liner, so if you are more experienced in another scripting language the same principle:

  • Check if the process is already running
  • If it is not running, start it

can of course be implemented in any language.

Syberdoor
  • 2,521
  • 1
  • 11
  • 14
  • Your's script is working properly for any kind of application except my Virtual Router's .bat file, because it's closing before VirtualRouter establish it's own network connection. With 10000 event trigger it's make loop. However you suggest me idea to keep process running longer than establishing connection of Virtual Router's network. I used WScript.Sleep 10000 in my vbs script. Thanks for that :) Now it's all working perfectly ;) – CamilloS Dec 24 '14 at 15:12
  • @CamilloS ah yeah that'S a problem. Glad to hear you solved your problem though. – Syberdoor Dec 25 '14 at 09:31