It is currently December 7th, 2021, 11:49 am

Can I close an application with Rainmeter?

Help with creating, editing & fixing problems with skins
User avatar
jsmorley
Developer
Posts: 22419
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Can I close an application with Rainmeter?

Post by jsmorley »

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]

[MeasureClose]
Measure=Plugin
Plugin=RunCommand
Program=PowerShell
Parameter=taskkill /IM notepad++.exe

[MeterOne]
Meter=String
FontSize=13
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Close Notepad++
LeftMouseUpAction=[!CommandMeasure MeasureClose "Run"]
User avatar
jsmorley
Developer
Posts: 22419
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Can I close an application with Rainmeter?

Post by jsmorley »

sl23 wrote: July 31st, 2021, 12:11 pm Powershell scares me though! O.O :o :lol:
Well in this case, nothing says you have to use Powershell. I'm just trying to train myself to use it over cmd.exe, since Powershell is the future.

You will quickly run out of the capabilities of cmd.exe, but likely never the far, far more robust Powershell.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]

[MeasureClose]
Measure=Plugin
Plugin=RunCommand
Parameter=taskkill /IM notepad++.exe

[MeterOne]
Meter=String
FontSize=13
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Close Notepad++
LeftMouseUpAction=[!CommandMeasure MeasureClose "Run"]
This will just use the default cmd.exe as the "Program" in RunCommand.
User avatar
sl23
Posts: 929
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Can I close an application with Rainmeter?

Post by sl23 »

Powershell/cmd all the same to me. I don't really get into that side of things. I've dabbled a little, very rarely though.

But thanks for the code, much appreciated.

Just curious though, why not use a .bat file seeing as the parameter for closing the app is the same? Is it just because it's safer than using a .bat file?
User avatar
jsmorley
Developer
Posts: 22419
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Can I close an application with Rainmeter?

Post by jsmorley »

sl23 wrote: July 31st, 2021, 12:30 pm Powershell/cmd all the same to me. I don't really get into that side of things. I've dabbled a little, very rarely though.

But thanks for the code, much appreciated.

Just curious though, why not use a .bat file seeing as the parameter for closing the app is the same? Is it just because it's safer than using a .bat file?
No, a .bat file is ok. Just seems kinda pointless to have to include an external file, when there is really no need.
User avatar
sl23
Posts: 929
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Can I close an application with Rainmeter?

Post by sl23 »

Very true! I like your thinking :D
User avatar
jsmorley
Developer
Posts: 22419
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Can I close an application with Rainmeter?

Post by jsmorley »

As far as Powershell, nothing to be afraid of really. It's a nice, reasonably easy command language. The reason I say it is the future, and cmd.exe is the past, is that Windows itself is going to be pushing it as the default command window.

If you look at the right-click menu of Start in Windows 11, you will see that it only offers Window Terminal, which by default opens up with a Powershell interface. You can get to cmd.exe in it, but it's an extra step.


1.jpg

2.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
sl23
Posts: 929
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Can I close an application with Rainmeter?

Post by sl23 »

So, for multiple programs, could you use:

Code: Select all

[MeasureClose]
Measure=Plugin
Plugin=RunCommand
Program=PowerShell
Parameter=taskkill /IM App1.exe
Parameter2=taskkill /IM App2.exe
Parameter3=taskkill /IM App3.exe
Parameter4=taskkill /IM App4.exe

[MeterOne]
Meter=String
FontSize=13
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Close Programs
LeftMouseUpAction=[!CommandMeasure MeasureClose "Run"]
User avatar
sl23
Posts: 929
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Can I close an application with Rainmeter?

Post by sl23 »

I think the only reason I avoid cmd/powershell is due to it's ability to ruin your PC! But also, I just haven't had the need to use it, except when a PC breaks! :lol: I even tried Linux Mint once, but found it buggy as hell and I missed my windows apps and integration too much :oops:

Btw, that code worked a treat, thank you. Now I just need to figure out how to get it working in my skin! :sly:
User avatar
jsmorley
Developer
Posts: 22419
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Can I close an application with Rainmeter?

Post by jsmorley »

sl23 wrote: July 31st, 2021, 12:42 pm So, for multiple programs, could you use:

Code: Select all

[MeasureClose]
Measure=Plugin
Plugin=RunCommand
Program=PowerShell
Parameter=taskkill /IM App1.exe
Parameter2=taskkill /IM App2.exe
Parameter3=taskkill /IM App3.exe
Parameter4=taskkill /IM App4.exe

[MeterOne]
Meter=String
FontSize=13
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Close Programs
LeftMouseUpAction=[!CommandMeasure MeasureClose "Run"]
No, the RunCommand plugin does not support multiple parameters like that.

You can stack up commands to Powershell on the command line with ; though.

Code: Select all

[MeasureClose]
Measure=Plugin
Plugin=RunCommand
Program=PowerShell
Parameter=taskkill /IM Notepad++.exe;taskkill /IM autoruns.exe
User avatar
sl23
Posts: 929
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Can I close an application with Rainmeter?

Post by sl23 »

Superb! Thanks