Page 2 of 2 FirstFirst 12
  1.    09 Jun 2017 #11
    Join Date : Oct 2013
    A Finnish expat in Germany
    Posts : 12,976
    Windows 10 Pro

    Quote Originally Posted by CWGilley View Post
    Thank you Sir. You have a good day and weekend too.
    LOL! You too, have a good weekend!

    Just to complete this "Command Prompt / PowerShell 101", here's something you might not have known: You can run PowerShell in Command Prompt window, and Command Prompt in PowerShell window.

    When in PowerShell, just type cmd and press Enter to switch to Command Prompt Mode. To indicate which mode you are using, see the prompt (highlighted yellow); In PowerShell mode, the prompt starts with letters PS (#1 in screenshot below), in Command Prompt mode those letters are missing from prompt (#2). When you exit Command Prompt mode with command exit returning to PowerShell mode, letters PS are again shown at beginning of the prompt (#3):

    Click image for larger version. 

Name:	image.png 
Views:	1 
Size:	179.3 KB 
ID:	138703

    And vice versa; when in Command Prompt, you can switch to PowerShell mode with command powershell and switch back to Command Prompt mode with command exit. In Command Prompt mode the letters PS in prompt are not shown (#1 and #3 in screenshot), whereas they are shown in PowerShell mode (#2):

    Click image for larger version. 

Name:	image.png 
Views:	1 
Size:	152.8 KB 
ID:	138704

    Kari
      My ComputerSystem Spec
  2.    18 Jun 2017 #12
    Join Date : Jun 2017
    Posts : 3
    Windows 10
    Thread Starter

    The file I am starting with the Task Scheduler has a type extension "bat." If that isn't sufficient to cause it to run under Command interpreter and not Power Shell, can I add a qualifier in the Task Scheduler? I really don't want to edit every line of the bat file. Or maybe the Task Scheduler could start cmd and the actual bat file could be specified in the additional parameter?

    I produce a log file using commands like time /T > c:\bat\test.log. The time-date stamp on the log file is proof that the bat job ran when it was scheduled.

    Quote Originally Posted by Kari View Post
    Yes and no

    OP's original post clearly has the batch file wrong typed due missing line breaks.

    If we look that test batch with added line breaks, as it should be, it looks like this:

    Code:
    time /T > c:\bat\test.log
    echo "--------------- starting test" >> c:\bat\test.log
    echo "-------------- finished test" >> c:\bat\test.log
    time /T >> c:\bat\test.log
    pause

    To be sure this will be run in Command Prompt mode, it would need to be edited like this:

    Code:
    cmd /c time /T > c:\bat\test.log
    cmd /c echo "--------------- starting test" >> c:\bat\test.log
    cmd /c echo "-------------- finished test" >> c:\bat\test.log
    cmd /c time /T >> c:\bat\test.log
    cmd /c pause

    The cmd /c prefix is usually only needed when running command line commands with parameters in PowerShell, but it does no harm and can be used also in Command Prompt. When the prefix is used, command will be run in Command Prompt regardless if it is started from Command Prompt, PowerShell or WIN + R prompt.

    Kari
      My ComputerSystem Spec
  3.    18 Jun 2017 #13
    Join Date : Oct 2013
    A Finnish expat in Germany
    Posts : 12,976
    Windows 10 Pro

    Quote Originally Posted by Old Professor View Post
    The file I am starting with the Task Scheduler has a type extension "bat." If that isn't sufficient to cause it to run under Command interpreter and not Power Shell, can I add a qualifier in the Task Scheduler?
    First, this issue of yours is interesting; I have never seen a batch file (.bat or .cmd) when run as a task to start PowerShell instead of Command Prompt.

    That being said, this should take care of that:

    Click image for larger version. 

Name:	image.png 
Views:	11 
Size:	77.8 KB 
ID:	140148

    Program: cmd, argument: /c MyBatchFile.bat

    When saved it looks like this:

    Click image for larger version. 

Name:	image.png 
Views:	11 
Size:	79.4 KB 
ID:	140149

    Kari
      My ComputerSystem Spec
  4.    18 Jun 2017 #14
    Join Date : Apr 2015
    Posts : 268
    Windows 10 Home x64 and Pro x86

    Old professor,

    Your test file runs correctly & pauses as intended when run from my [Ver 1703] Task scheduler without any special syntax being necessary.

    The discussion about Powershell is not relevant to your problem. Somebody else mentioned it and then the others thought that you had said that it was running in Powershell.

    If you simplified your real batch file for ease of explanation in this forum then might it be that some error is occurring and that it is crashing before reaching the pause line?. Are you running the real batch using the same user account you are testing it in?

    Does your batch file appear correctly if you open it in Notepad?
    time /T > c:\bat\test.log
    echo "--------------- starting test" >> c:\bat\test.log
    echo "-------------- finished test" >> c:\bat\test.log
    time /T >> c:\bat\test.log
    pause

    Whatever your problem is, it has nothing to do with Powershell.

    Denis
      My ComputerSystem Spec
  5.    19 Jun 2017 #15
    Join Date : Oct 2013
    A Finnish expat in Germany
    Posts : 12,976
    Windows 10 Pro

    Quote Originally Posted by Try3 View Post
    The discussion about Powershell is not relevant to your problem. Somebody else mentioned it and then the others thought that you had said that it was running in Powershell.

    Whatever your problem is, it has nothing to do with Powershell.
    I mentioned this in my last post, also sceptical about a batch "running in PowerShell":

    Quote Originally Posted by Kari View Post
    First, this issue of yours is interesting; I have never seen a batch file (.bat or .cmd) when run as a task to start PowerShell instead of Command Prompt.

    However, you are only half right right: OP mentioned it by himself, although first after it was suggested:

    Quote Originally Posted by Caledon Ken View Post
    I can't be 100% certain but there is this shift going on from Command Prompt to Powershell in Windows 10..
    Quote Originally Posted by Old Professor View Post
    But when I start test.bat from the Task Scheduler, it appears that you are correct in that it runs in Powershell,
      My ComputerSystem Spec

 
Page 2 of 2 FirstFirst 12


Similar Threads
Thread Forum
Backup & Restore Import Task to Task Scheduler in Windows
How to Import a Task to Task Scheduler in Windows The Task Scheduler enables you to automatically perform routine tasks on a chosen computer. The Task Scheduler does this by monitoring whatever criteria you choose to initiate the tasks (referred...
Tutorials
Backup & Restore Export Task from Task Scheduler in Windows
How to Export a Task from Task Scheduler in Windows The Task Scheduler enables you to automatically perform routine tasks on a chosen computer. The Task Scheduler does this by monitoring whatever criteria you choose to initiate the tasks...
Tutorials
No restore from Seagate. Windows task scheduler can't be started
I am trying to restore a file from a Seagate external drive. The backup seems to be working OK, but when I try to restore, I get a message "Windows Task Scheduler cannot be started. Please check if the Task Scheduler service is active before...
Backup and Restore
How to show Command Prompt Window when running task in Task Scheduler?
Is there a way to make the "Command Prompt" window show when I have a task running in Windows task Scheduler? I would like to be able to view the progress of the task. For example, I have a program called "Zap2xml" that collects TV EPG data. It...
General Support
Solved Time Zone change causes error in Task Scheduler for every task
My issue is kind of strange. I am an insider currently on Windows 10 build 10240. All the build I have tried so far has this same error in task scheduler when I change my time zone to my current location which is kathmandu (UTC+5:45). When i change...
Performance & Maintenance
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd
All times are GMT -5. The time now is 00:49.
Find Us
Twitter Facebook Google+ Ten Forums iOS App Ten Forums Android App



Windows 10 Forums