0

I have a question I have this batch code

@echo off 
taskkill /F /FI "STATUS eq running" /FI "USERNAME ne NT AUTHORITY\SYSTEM" /FI "USERNAME ne NT AUTHORITY\LOCAL SERVICE" /FI "USERNAME ne NT AUTHORITY\NETWORK SERVICE" 
shutdown /s /f /t 0 

[I want the computer to shutdown when it finishes running, but it only closes all current processes, not shutdown]?

Is there any way to finish running the above code and the computer will shut down perfectly? thank you guys !

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • Can't replicate, /f should bring your PC to shutdown ignoring any apps that try to block it. What does your event log say? – Martheen Sep 01 '23 at 01:16
  • If you want to shutdown Windows using `%SystemRoot%\System32\shutdown.exe` and having the permission to really trigger a shutdown of Windows with the used account, why do you __brutally kill__ with `%SystemRoot%\System32\taskkill.exe` with using option `/F` by the operating system all running applications first without giving them the chance to gracefully terminate themselves with closing all opened connections, finishing write operations on files or on registry, saving if necessary and closing opened files? Do you like corrupting files and registry frequently? – Mofi Sep 01 '23 at 06:19
  • BTW: The second command line is the reason why the computer is not shutdown in your case. A batch file is processed by the *Windows Command Processor* `cmd.exe`. The second command line results in __brutally killing__ by Windows all processes started with the current user account which includes `cmd.exe` processing the batch file. For that reason the third command line is never processed by `cmd.exe` and `shutdown` is therefore never executed by `cmd.exe`. Change the batch file to `@%SystemRoot%\System32\shutdown.exe /f /s /t 0` and the shutdown of Windows should work as expected by you. – Mofi Sep 01 '23 at 06:25
  • BTW: There is no batch file needed at all if the batch file contains now really just this single command line without `@echo off` and without the counterproductive and really harmful `taskkill` command line. There could be used also a __shortcut__ file (`.lnk` file) with property __Target__ being `C:\Windows\System32\shutdown.exe /f /s /t 0` and property __Start in__ defined with `C:\Windows\System32` which can be used to shutdown the Windows computer. There can be a __Shortcut key__ defined to quickly shutdown the computer with pressing this key combination on keyboard. – Mofi Sep 01 '23 at 06:30
  • What is the purpose of killing only some processes, then immediately afterwards force closing everything? – Compo Sep 01 '23 at 09:19
  • I often work and sleep late and when I turn off the computer I often have to close each task. I don't like that so I came up with this . Thank you very much for your attention to my question ! – Ngo Thang Sep 03 '23 at 00:59
  • Because I have had a few times when I turned off the computer but the tasks did not automatically close. When come back, the screen is still bright a few hours ! – Ngo Thang Sep 03 '23 at 01:20

0 Answers0