If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
scheduling an event whenever i connect to a wired network
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? |
Ads |
#2
|
|||
|
|||
scheduling an event whenever i connect to a wired network
"yawnmoth" wrote in message ... 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 1nul 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. |
#3
|
|||
|
|||
scheduling an event whenever i connect to a wired network
On Sep 26, 1:43*pm, "Pegasus [MVP]" wrote:
"yawnmoth" wrote in message ... 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 1nul 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% Interesting. So I guess the vbscript just runs constantly, in the background? Are there situations where it could bog down system performance? Does cMonitoredEvents.NextEvent block until there's a change? Also, what other tables are there? There's MSNDIS_StatusMediaConnect... are there any other tables? |
#4
|
|||
|
|||
scheduling an event whenever i connect to a wired network
"yawnmoth" wrote in message ... On Sep 26, 1:43 pm, "Pegasus [MVP]" wrote: "yawnmoth" wrote in message ... 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 1nul 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% Interesting. So I guess the vbscript just runs constantly, in the background? Are there situations where it could bog down system performance? Does cMonitoredEvents.NextEvent block until there's a change? Also, what other tables are there? There's MSNDIS_StatusMediaConnect... are there any other tables? ========= It is cscript.exe that runs constantly in the background (and that can be killed with taskkill.exe if you so desire). I do not think that the MSNdis_StatusMediaConnect event class causes any significant CPU loading but then you can easily work this out for yourself by keeping the script running for an hour before checking how much CPU time the cscript.exe process has clocked up. About other event classes - other than MSNDIS-StatusMediaDisconnect I do not know. If you have a lot of patience then you can google for these two classes. You will get some Microsoft TechNet pages which are likely to contain a list of available classes. |
#5
|
|||
|
|||
scheduling an event whenever i connect to a wired network
"yawnmoth" wrote in message ... On Sep 26, 1:43 pm, "Pegasus [MVP]" wrote: "yawnmoth" wrote in message ... 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 1nul 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% Interesting. So I guess the vbscript just runs constantly, in the background? Are there situations where it could bog down system performance? Does cMonitoredEvents.NextEvent block until there's a change? Also, what other tables are there? There's MSNDIS_StatusMediaConnect... are there any other tables? ============== Correction: It's probably both cscript.exe and wmiprvse.exe that you need to monitor when checking processor loading. |
Thread Tools | |
Display Modes | |
|
|