how to prevent .batch file focus steal executed from a taskschedular


  1. Posts : 205
    10, server 2016, server2012
       #1

    how to prevent .batch file focus steal executed from a taskschedular


    I have the codes below
    taskkill /F /T /IM AAA.exe
    start /MIN "" "C:\Users\Administrator\AAA.exe" :0
    ping 127.0.0.1 -n 5 > nul
    taskkill /F /T /IM CCC.exe
    start /MIN "" "C:\Program Files (x86)\CCC.exe" :0
    exit
    setup with task scheduler to run this every hour, but the focus steal from CMD window is too much. how can this be written to prevent it?
      My Computer


  2. Posts : 34,278
    10 Home x64 (22H2) (10 Pro on 2nd pc)
       #2

    m18xr2 said:
    ...setup with task scheduler to run this every hour, but the focus steal from CMD window is too much. how can this be written to prevent it?
    Try this....

    How to prevent command window from appearing on scheduled tasks on Windows 10 - Pureinfotech
      My Computers


  3. Posts : 17,099
    Windows 10 Home x64 Version 22H2 Build 19045.5371
       #3

    m18xr2 said:
    ...the focus steal from CMD window is too much. how can this be written to prevent it?
    To run something without it stealing focus requires use of VBS.
    So it is not a question of modifying what you have now but using VBS to do the job or, at least, using VBS to start it.


    I assume you mean that you are running those commands in a batch file from Task scheduler.
    I assume you mean that the command window is stealing the focus rather than something is stealing focus from it.


    I do not know why you are using the Built-in Admin account.
    I do not know why you are putting executable files in any user account folder.


    This approach should achieve what you want
    Make Task scheduler run a batch file minimised and with a specific icon - TenForums
    Despite its title, it also covers the option to run the batch file hidden.
    In both cases, hidden & minimised, the batch file will run without stealing focus.


    Denis
    Last edited by Try3; 21 Feb 2023 at 06:25.
      My Computer


  4. Posts : 205
    10, server 2016, server2012
    Thread Starter
       #4

    doing this only execute the taskkill part but not the start program part. not sure why.

    Try3 said:
    To run something without it stealing focus requires use of VBS.
    So it is not a question of modifying what you have now but using VBS to do the job or, at least, using VBS to start it.

    I assume you mean that you are running those commands in a batch file from Task scheduler.
    I assume you mean that the command window is stealing the focus rather than something is stealing focus from it.

    I do not know why you are using the Built-in Admin account.
    I do not know why you are putting executable files in any user account folder.

    This approach should achieve what you want
    Make Task scheduler run a batch file minimised and with a specific icon - TenForums
    Despite its title, it also covers the option to run the batch file hidden.
    In both cases, hidden & minimised, the batch file will run without stealing focus.

    Denis
    reason killing task and restarting is because it'll lockup and im tired of restarting them manually. when the application locks up it requires me entering into task manager, kill the task then manually fire it up again.

    built in admin account is because using server window 2016 which is basically same as windows10, defaults to administrator and i'll be the only one using it, kind of like a test matchine.

    i'll give the VBS thing a try, thanks
      My Computer


  5. Posts : 1,208
    11 Home
       #5

    m18xr2 said:
    built in admin account is because using server window 2016 which is basically same as windows10, defaults to administrator and i'll be the only one using it, kind of like a test matchine.
    No. The built-in admin account exists mainly because you can use it to still get in after your other user account(s) get(s) corrupted somehow. Using the built-in admin account as a typical replacement for a separate admin account was not, is not, will not be recommended in any way─even if you can.
      My Computers


  6. Posts : 1,208
    11 Home
       #6

    Try3 said:
    I do not know why you are putting executable files in any user account folder.
    Even M$ puts executables in %LocalAppData%\Programs. %LocalAppData% points to %UserProfile%\AppData\Local.
      My Computers


  7. Posts : 17,099
    Windows 10 Home x64 Version 22H2 Build 19045.5371
       #7

    m18xr2 said:
    doing this only execute the taskkill part but not the start program part. not sure why.
    Perhaps the user account that runs the task does not have access to the folder containing your Start command.

    MS, just for example, only puts executables within the user folders when an application has been installed just for that specific user so access problems are not relevant.

    Denis
      My Computer


  8. Posts : 1,208
    11 Home
       #8

    Under Step 6 in that tutorial, if the batchfile needs to run with admin rights, then be sure to also check the "Run with highest privileges" (checkbox at the bottom). In the new Action where you choose "Start a program", put %windir%\System32\wscript.exe under "Program/script:", and, next to "Add parameters (optional):", put the full filepath of the .vbs file enclosed in doublequotes. The .vbs file that runs the batchfile invisibly and doesn't steal the focus can be written like this:
    CreateObject("WScript.Shell").Run """%windir%\System32\cmd.exe"" /c start """" ""filepath""", 0
    Substitute filepath in the above with the full filepath of the batchfile.
      My Computers


 

  Related Discussions
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 07:59.
Find Us




Windows 10 Forums