yawnmoth said:
Events can be scheduled to run at a certain time via the Windows
Scheduler. What if you wanted to trigger an event to run during a
certain "event". ie. make it so one event triggers another?
Here you go:
@echo off
set BatchName=d:\temp\test.bat
set Scr=c:\TempVBS.vbs
set VB=echo^>^>%Scr%
cd 1>nul 2>%Scr%
%VB% Set oWshShell = CreateObject("WScript.Shell")
%VB% Set oWMIService = GetObject("winmgmts:\\.\root\wmi")
%VB% Set cMonitoredEvents = oWMIService.ExecNotificationQuery _
%VB% ("Select * from MSNDIS_StatusMediaConnect")
%VB% Do While True
%VB% Set sLatestEvent = cMonitoredEvents.NextEvent
%VB% oWshShell.Run "cmd.exe /c %BatchName% " _
%VB% ^& sLatestEvent.InstanceName
%VB% Loop
start /b cscript //nologo %Scr%
ping localhost -n 10 > nul
del %Scr%
Line 2 contains a reference to the command you wish to execute when you plug
in your network cable, d:\temp\test.bat in this case. It might contain the
following lines:
@echo off
echo %date% %time:~0,5% %* >> d:\test.txt
To make maintenance easier, you could combine the two batch files in a
single batch file and invoke either one component or the other, depending on
the parameter you supply.