none
In a DOS script, is there a way to identify if the script is being run from the CMD line or as a Scheduled Task ?

Răspunsuri

  • Another solution ...

    If the parent process id of the batch is the Taskeng.exe process id we are "inside" a scheduled task ...

    @echo off setlocal

    set cmd=%~0 set okcmd=%cmd:\=\\% wmic process where "commandline like "%%%okcmd%%%" and not caption="wmic.exe"" get ParentProcessId 2>nul |findstr /v /i "ParentProcessId" 1>"%temp%\_ppid.txt" set /p ppid= <"%temp%\_ppid.txt" if not defined ppid (echo %0 run from a command line "%temp%\_log.txt" tasklist /fi "imagename eq taskeng.exe" /nh |findstr /i " %ppid% " && echo %0 run from a Scheduled Task >"%temp%\_log.txt" )



    Gastone Canali >http://www.armadillo.it

    Se alcuni post rispondono al tuo quesito (non necessariamente i miei), ricorda di contrassegnarli come risposta e non dimenticare di contrassegnare anche i post utili . GRAZIE!


    19 martie 2012 00:24
  • Add named arhgument that will be set in scheduler.

    /scheduled true

    Check this in the script.


    ¯\_(ツ)_/¯

    18 martie 2012 20:17

Toate mesajele

  • You can have a look on what all scheduled tasks got triggered and the completion status by checking the scheduled task log. But its difficult to track the other way.

    Shaba

    18 martie 2012 13:43
  • If you launch the scheduled task under a dedicated scheduler account (which is recommended in most cases) then you can examine the %UserName% environmental variable to tell how the batch file got invoked.
    18 martie 2012 20:07
  • Add named arhgument that will be set in scheduler.

    /scheduled true

    Check this in the script.


    ¯\_(ツ)_/¯

    18 martie 2012 20:17
  • Another solution ...

    If the parent process id of the batch is the Taskeng.exe process id we are "inside" a scheduled task ...

    @echo off setlocal

    set cmd=%~0 set okcmd=%cmd:\=\\% wmic process where "commandline like "%%%okcmd%%%" and not caption="wmic.exe"" get ParentProcessId 2>nul |findstr /v /i "ParentProcessId" 1>"%temp%\_ppid.txt" set /p ppid= <"%temp%\_ppid.txt" if not defined ppid (echo %0 run from a command line "%temp%\_log.txt" tasklist /fi "imagename eq taskeng.exe" /nh |findstr /i " %ppid% " && echo %0 run from a Scheduled Task >"%temp%\_log.txt" )



    Gastone Canali >http://www.armadillo.it

    Se alcuni post rispondono al tuo quesito (non necessariamente i miei), ricorda di contrassegnarli come risposta e non dimenticare di contrassegnare anche i post utili . GRAZIE!


    19 martie 2012 00:24
  • Gastone - nice way to do it for batch scripts.  Excellente!

    ¯\_(ツ)_/¯

    19 martie 2012 00:34
  • Gastone - nice way to do it for batch scripts.  Excellente!

    ¯\_(ツ)_/¯


    Thanks!

    Gastone Canali >http://www.armadillo.it

    Se alcuni post rispondono al tuo quesito (non necessariamente i miei), ricorda di contrassegnarli come risposta e non dimenticare di contrassegnare anche i post utili . GRAZIE!

    23 martie 2012 00:14