Close a command prompt CMD?

Solved
Dkeagle1911 Posted messages 57 Status Member -  
crapoulou Posted messages 28002 Registration date   Status Moderator, Security Contributor Last intervention   -
Hello,

I wrote a small batch script intended to restart a program as simply as possible:
@echo off taskkill /im software.exe /F "C:\Program Files\folder\software.exe" exit 


The program restarts in 1/10 of a second, no problem...
Well, yes!

As soon as the "taskkill" executes, it opens a command prompt just to tell me
"Operation successful: the process "software.exe" with PID 9999 has been terminated."

How can I close this window directly (or even prevent it from appearing at all)? Its appearance breaks the simple principle of my script...

Thank you!

Configuration: Windows 7 / Chrome 54.0.2840.59

5 answers

  1. fabul Posted messages 42168 Registration date   Status Moderator Last intervention   6 069
     
    Hello,

    To close
    :quit

    Or quit without the :

    Or you can convert a .bat to .exe with bat to exe converter

    It seems to me that the cmd window doesn't show up, or if you don't want it to.

    https://www.commentcamarche.net/telecharger/developpement/4555-bat-to-exe-converter/
    4
    1. Dkeagle1911 Posted messages 57 Status Member 8
       
      Hello,

      the :quit doesn't change anything, it still opens a cmd window to tell me that the operation is successful

      the quit (without the :) simply tells me that "quit is not a valid Windows command"

      I'm testing by converting the .bat to .exe and I'll keep you updated
      0
    2. Dkeagle1911 Posted messages 57 Status Member 8
       
      Well, that's great, it's restarting everything without any issues, perfect ^^

      Thank you very much
      I’ll mark the topic as "resolved"
      0
      1. crapoulou Posted messages 28002 Registration date   Status Moderator, Security Contributor Last intervention   8 046 > Dkeagle1911 Posted messages 57 Status Member
         
        Sure, thank you for your feedback.
        0
  2. crapoulou Posted messages 28002 Registration date   Status Moderator, Security Contributor Last intervention   8 046
     
    Hello,

    Try this:

    @echo off taskkill /im software.exe /F >nul "C:\Program Files\folder\software.exe" exit
    1
    1. Dkeagle1911 Posted messages 57 Status Member 8
       
      I had seen it on another page, the ">nul", I tried but nothing works...
      It always opens a CMD, which is empty (instead of displaying "Operation successful, etc.", but it appears anyway)
      0
    2. crapoulou Posted messages 28002 Registration date   Status Moderator, Security Contributor Last intervention   8 046 > Dkeagle1911 Posted messages 57 Status Member
       
      Strange, I do it at home and the CMD opens up, runs the program, then closes (with the Exit command).

      Do you end up with a cmd open with your command and that's it?
      Can you send a screenshot?
      0
    3. crapoulou Posted messages 28002 Registration date   Status Moderator, Security Contributor Last intervention   8 046 > Dkeagle1911 Posted messages 57 Status Member
       
      Don't you have the same video with the >nul?
      Because yes, the cmd window opens and closes automatically, right?!

      If so, that's normal behavior!
      0
    4. Dkeagle1911 Posted messages 57 Status Member 8
       
      No, I don't have a video with the >null, but the only change is that the cmd window, instead of displaying "Operation successful" etc., simply shows nothing
      but it is still there and unfortunately does not close by itself
      I have to go and close it myself by clicking on it,

      for an operation that I wanted to be simple and quick with a .bat file, that's one click too many xD
      0
  3. REMYMARTIN60 Posted messages 2016 Status Member 403
     
    Hello, I don’t know if I can help you, but here’s how I personally use my taskkill on Windows 10:

    C:\Windows\System32\taskkill.exe /F /FI "USERNAME eq *session_name* /FI "IMAGENAME ne explorer.exe" /FI "IMAGENAME ne dwm.exe" /FI "IMAGENAME ne sihost.exe"

    This has the effect of closing EVERYTHING except explorer.exe / dwm.exe and sihost.exe

    and I don't have any window left open

    In doubt, reboot! When it fails, format!
    LePetitJimmy
    0
  4. Dkeagle1911 Posted messages 57 Status Member 8
     
    I just made a short video of the problem, so that everyone understands exactly WHERE it is...

    The code executes fine, Rainmeter, which manages my desktop, restarts properly (you can see it restarting in the video)
    but the code opens a CMD just to confirm that it has indeed closed the process before restarting it, and this window, I have to close it manually

    https://www.youtube.com/watch?v=6dH0EHp5f1M&feature=youtu.be

    Thank you ^^
    0
    1. REMYMARTIN60 Posted messages 2016 Status Member 403
       
      /F >null
      0
    2. Dkeagle1911 Posted messages 57 Status Member 8
       
      As I mentioned in my response to Crapoulou, the >nul after Taskkill allows you to "clear" the window (the "Operation successful" message does not appear, but the window, even empty, still opens...).
      0
  5. Dkeagle1911 Posted messages 57 Status Member 8
     
    Anyone?
    0