Home All Groups Group Topic Archive Search About

How to differentiate between a program launched manually and launched by a windows task scheduler ??

Author
5 Jan 2007 9:13 PM
mayur_hirpara
Hi,
I am writing a VB.NET application. It is a Windows application at the
moment.
The application contains a button. the click event of button perform a
long running task.
It needs to be started by windows task scheduler to carry out some
operation.

When I am testing the application I want to differentiate if the
"differentiate between a program launched manually and launched by a
windows task scheduler" so that in the load event of form I can call
the function which carries out long running task when application is
started by scheduler OR else if it ws launched manually then nothing
will happen automatically. USer will have to click the button to
perform the operation.

Again can someone show me ....
How to differentiate between a program launched manually and launched
by a windows task scheduler ???

Any help is greatly appreciated....
Thanks in advance,
--Mike.

Author
6 Jan 2007 8:55 AM
Mattias Sjögren
>How to differentiate between a program launched manually and launched
>by a windows task scheduler ???

I think the easiest way is to configure Task Scheduler to pass in an
extra command line parameter that you then can check for in your Main
procedure.


Mattias

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Author
6 Jan 2007 9:09 AM
Eugene Mayevski
Hello!
You wrote  on 5 Jan 2007 13:13:54 -0800:

mh> Again can someone show me ....
mh> How to differentiate between a program launched manually and launched
mh> by a windows task scheduler ???

http://vbnet.mvps.org/index.html?code/system/getparentprocess.htm

With best regards,
Eugene Mayevski
http://www.SecureBlackbox.com - the comprehensive component suite for
network security
Author
8 Jan 2007 10:17 PM
mayur_hirpara
Great...
Thanks...It works after a little tweak to the parameter types from long
to integer and same for return types may be because I am on windows XP
SP@ at the moment.
In the course of solving this problem I alos found some elegent code
that worked same way...

http://www.csharpfriends.com/Forums/ShowPost.aspx?PostID=27395

and
microsoft.public.dotnet.framework
http://groups.google.to/group/microsoft.public.dotnet.framework.aspnet/browse_thread/thread/9567b59857e8231e/9c1da01e43c2ff49?lnk=st&q=dotnet+th32ParentProcessID+-herfried&rnum=8#9c1da01e43c2ff49

Thanks a ton any way for such prompt help...
--Mike


Eugene Mayevski wrote:
Show quote
> Hello!
> You wrote  on 5 Jan 2007 13:13:54 -0800:
>
>  mh> Again can someone show me ....
>  mh> How to differentiate between a program launched manually and launched
>  mh> by a windows task scheduler ???
>
> http://vbnet.mvps.org/index.html?code/system/getparentprocess.htm
>
> With best regards,
> Eugene Mayevski
> http://www.SecureBlackbox.com - the comprehensive component suite for
> network security

AddThis Social Bookmark Button