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 ?
-
18 martie 2012 13:29
It's all in the Title I guess ?
Cheers, Cameron Young
Toate mesajele
-
18 martie 2012 13:43You 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 20:07If 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:17
Add named arhgument that will be set in scheduler.
/scheduled true
Check this in the script.
¯\_(ツ)_/¯
- Propus ca răspuns de GastoneCanaliMicrosoft Community Contributor 19 martie 2012 00:24
- Marcat ca răspuns de IamMredMicrosoft Employee, Owner 25 martie 2012 05:19
-
19 martie 2012 00:24
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!- Editat de GastoneCanaliMicrosoft Community Contributor 19 martie 2012 00:27
- Propus ca răspuns de GastoneCanaliMicrosoft Community Contributor 23 martie 2012 00:10
- Marcat ca răspuns de IamMredMicrosoft Employee, Owner 25 martie 2012 05:19
-
19 martie 2012 00:34Gastone - nice way to do it for batch scripts. Excellente!
¯\_(ツ)_/¯
-
23 martie 2012 00:14
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!