Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Confused: batch file to kill itself ?!?!  (Read 5142 times)

0 Members and 1 Guest are viewing this topic.

locbtran

    Topic Starter


    Rookie

    Confused: batch file to kill itself ?!?!
    « on: February 06, 2009, 05:43:50 PM »
    What I'm trying to do is, if an old instance of my batch file is currently running, then I would like my batch file to kill it and start a new instance.  I can do this in Java, but is this possible using a batch file?

    I tried using taskkill or pskill to kill the old process but to no avail!!!!!!!!!
    taskkill /IM "cmd.exe"
    or
    pskill "cmd.exe"

    Any comment or suggestion is always appreciated.

    Hedonist



      Intermediate

      Re: Confused: batch file to kill itself ?!?!
      « Reply #1 on: February 06, 2009, 09:36:12 PM »
      Could be difficult.  With two or more Cmd.exe windows open all relevant processes are named Cmd.exe, how can Taskill determine which one to terminate unless you quote the PID.  So Taskkill will terminate all Cmd.exe processes including the CMD.exe which is currently running your batch script..

      Worth investigating tho', hope someone comes up with an answer.


      Geek-9pm


        Mastermind
      • Geek After Dark
      • Thanked: 1026
        • Gekk9pm bnlog
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: Confused: batch file to kill itself ?!?!
      « Reply #2 on: February 06, 2009, 09:52:49 PM »
      I am not sure what you mean. A batch file will kill itself far too easy, without much effort! And why would you want another instance?

      Code: [Select]
      REM this.bat is a batch that kills itself by invoking itself.
      THIS.BAT

      So, that is not what you meant?

      locbtran

        Topic Starter


        Rookie

        Re: Confused: batch file to kill itself ?!?!
        « Reply #3 on: February 06, 2009, 11:45:03 PM »
        My batch file checks if the application is NOT running then starts up my application else it does nothing and also starts a batch menu.  When I accidently close one of my applications, I just double click on my batch file and it starts up the application that was close but it also launches another instance of my batch menu.  So there's two instance of cmd.exe running. 

        I know I would be alot easier if I had 2 batch files, one to start up all the applications and the other just for a batch menu but where's the challenge and fun in that?

        thanks

        Geek-9pm


          Mastermind
        • Geek After Dark
        • Thanked: 1026
          • Gekk9pm bnlog
        • Certifications: List
        • Computer: Specs
        • Experience: Expert
        • OS: Windows 10
        Re: Confused: batch file to kill itself ?!?!
        « Reply #4 on: February 07, 2009, 11:26:59 AM »
        Quote
        where's the challenge and fun in that?

        Yeah.  ::)

        BC_Programmer


          Mastermind
        • Typing is no substitute for thinking.
        • Thanked: 1140
          • Yes
          • Yes
          • BC-Programming.com
        • Certifications: List
        • Computer: Specs
        • Experience: Beginner
        • OS: Windows 11
        Re: Confused: batch file to kill itself ?!?!
        « Reply #5 on: February 07, 2009, 11:59:10 AM »
        This type of thing requires all sorts of convolutions to get working in an actual programming language- such as C/C++, involving first determining wether a previous instance exists, getting it's processID, grabbing the top level window of that process, and sending an Application message to it with the command line arguments of the new instance, and then the new instance quits. the old instance processes the message and loads the command line- for example file names. Some would say to just use KillProcess on the old instance. Well that would A: destroy everything changed in the original documents in the first process, and B: possibly leave open handles to files and devices.


        Java has it easy since the VM will do all the real work.
        I was trying to dereference Null Pointers before it was cool.