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

Author Topic: Need Batch file to execute and close same program  (Read 1243 times)

0 Members and 1 Guest are viewing this topic.

kohgan

    Topic Starter


    Newbie

    • Experience: Familiar
    • OS: Windows 8
    Need Batch file to execute and close same program
    « on: October 20, 2017, 08:37:09 AM »
    Hello all.
    I have rainmeter on my system, and game alot. I'm trying to figure out how to create a single button on my desktop to open and close the program so as not to clutter my desktop with multiple icons for the same program. I currently have two separate files one for turning it on and the other for turning it off.

    To turn on rainmeter I have the following batch

    @echo off
    cd "C:\Program Files\Rainmeter"
    start Rainmeter.exe
    exit


    To turn off Rainmeter I have this batch

    taskkill /f /im rainmeter.exe


    Is there a way to combine these into a single batch file so I have only one button that does both optionally?

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1083
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 8
    Re: Need Batch file to execute and close same program
    « Reply #1 on: October 20, 2017, 09:18:09 PM »
    This should "toggle" when you run it. If it's running it is terminated, if it's not running, it is launched.

    Code: [Select]
    @echo off
    cd "C:\Program Files\Rainmeter"
    taskkill /f /im rainmeter.exe && echo "terminated Rainmeter" || rainmeter.exe
    exit
    I was trying to dereference Null Pointers before it was cool.

    Squashman



      Specialist
    • Thanked: 119
    • Experience: Experienced
    • OS: Other
    Re: Need Batch file to execute and close same program
    « Reply #2 on: October 24, 2017, 12:56:08 PM »
    Why not gracefully exit the program with the proper command line argument.

    Code: [Select]
    "C:\Program Files\Rainmeter\Rainmeter.exe" !Quit