I am trying to design a windows-service which monitors a process namely “Gtalk”, if the process is started then, the browser Internet-explorer (process iexplore) should be closed. This should happen only when the process “Gtalk” is started, [not when running]
The code I have written and implemented, doesn’t allow to open IExplore when Gtalk is running. That is certainly what not I am trying for. The process Gtalk should close browser only at its start-up, After the process is started, it should allow to open IExplore.
Is it possible with Windows service or is it must be the part of Gtalk process itself?
This is my code:
while (true)
{
if (Process.GetProcessesByName("Gtalk").Length > 0)
{
foreach (Process prc in Process.GetProcessesByName("IExplore"))
{
prc.Kill();
}
}
}
From what you’re saying (maybe I misread it), it’s only at startup of GTalk that this should kill IE, thereafter IE can be launched. Can multiple instances of GTalk be running?
Do you control the GTalk code? Sounds like it would be best implemented in the GTalk startup procedure.
If not then @peSHIr’s route of checking whether the GTalk process detected is one you’ve already seen might be your best bet.
However even if only one instance of GTalk can run, you would need to break out of the code that does the IE kill once first run (maybe storing the GTalk process ID), then periodically check (maybe utilizing a timer) if the GTalk process is running and if not (or if it is but with a different proccess ID) you would run the IE kill code again
Edit: simple example of Timer usage
Note that this timer object is Disposable,
Here’s a quick example;
null = state, 0L means run now, and the last parameter is your interval in milliseconds for how often this should run