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

Can I close an application with Rainmeter?

Help with creating, editing & fixing problems with skins
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 »

Sorry, one more thing...

What do these mean: /IM /T /F I can;'t seem to find any info about them. I've done a web search but the several pages I looked at for powershell commands don't show these.

I see the last two have been omitted in your code, I suppose /F is to force the app to close? Is /T for setting a time?
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 »

One thing to keep in mind is that RunCommand will open Powershell with the default security level.

If you need to execute a command that requires being run "As Administrator", it's a bit different.

Code: Select all

[MeasureClose]
Measure=Plugin
Plugin=RunCommand
Program=PowerShell
Parameter=Start-Process -FilePath "taskkill" -ArgumentList "/IM autoruns.exe" -verb RunAs
Since the program autoruns.exe is run with administrator access, killing it also requires administrator access. So you have to "elevate" the command when you run it. That is what the -verb RunAs does.
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, 1:00 pm Sorry, one more thing...

What do these mean: /IM /T /F I can;'t seem to find any info about them. I've done a web search but the several pages I looked at for powershell commands don't show these.

I see the last two have been omitted in your code, I suppose /F is to force the app to close? Is /T for setting a time?
Those are parameters for the built-in taskkill.exe in Windows...

Code: Select all

PS C:\Users\JSMorley> taskkill /?

TASKKILL [/S system [/U username [/P [password]]]]
         { [/FI filter] [/PID processid | /IM imagename] } [/T] [/F]

Description:
    This tool is used to terminate tasks by process id (PID) or image name.

Parameter List:
    /S    system           Specifies the remote system to connect to.

    /U    [domain\]user    Specifies the user context under which the
                           command should execute.

    /P    [password]       Specifies the password for the given user
                           context. Prompts for input if omitted.

    /FI   filter           Applies a filter to select a set of tasks.
                           Allows "*" to be used. ex. imagename eq acme*

    /PID  processid        Specifies the PID of the process to be terminated.
                           Use TaskList to get the PID.

    /IM   imagename        Specifies the image name of the process
                           to be terminated. Wildcard '*' can be used
                           to specify all tasks or image names.

    /T                     Terminates the specified process and any
                           child processes which were started by it.

    /F                     Specifies to forcefully terminate the process(es).

    /?                     Displays this help message.

Filters:
    Filter Name   Valid Operators           Valid Value(s)
    -----------   ---------------           -------------------------
    STATUS        eq, ne                    RUNNING |
                                            NOT RESPONDING | UNKNOWN
    IMAGENAME     eq, ne                    Image name
    PID           eq, ne, gt, lt, ge, le    PID value
    SESSION       eq, ne, gt, lt, ge, le    Session number.
    CPUTIME       eq, ne, gt, lt, ge, le    CPU time in the format
                                            of hh:mm:ss.
                                            hh - hours,
                                            mm - minutes, ss - seconds
    MEMUSAGE      eq, ne, gt, lt, ge, le    Memory usage in KB
    USERNAME      eq, ne                    User name in [domain\]user
                                            format
    MODULES       eq, ne                    DLL name
    SERVICES      eq, ne                    Service name
    WINDOWTITLE   eq, ne                    Window title

    NOTE
    ----
    1) Wildcard '*' for /IM switch is accepted only when a filter is applied.
    2) Termination of remote processes will always be done forcefully (/F).
    3) "WINDOWTITLE" and "STATUS" filters are not considered when a remote
       machine is specified.

Examples:
    TASKKILL /IM notepad.exe
    TASKKILL /PID 1230 /PID 1241 /PID 1253 /T
    TASKKILL /F /IM cmd.exe /T
    TASKKILL /F /FI "PID ge 1000" /FI "WINDOWTITLE ne untitle*"
    TASKKILL /F /FI "USERNAME eq NT AUTHORITY\SYSTEM" /IM notepad.exe
    TASKKILL /S system /U domain\username /FI "USERNAME ne NT*" /IM *
    TASKKILL /S system /U username /P password /FI "IMAGENAME eq note*"
 
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 »

Ah ok thanks for the tip on elevated tasks ;)
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, 1:11 pm Ah ok thanks for the tip on elevated tasks ;)
Sure. I'd be hesitant to distribute a skin that required an "elevated" command to Powershell though. The issue is that running it will cause UAC (User Account Control) to pop up a confirmation dialog, and that might be somewhat disconcerting to your users.
User avatar
Active Colors
Moderator
Posts: 919
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany

Re: Can I close an application with Rainmeter?

Post by Active Colors »

sl23 wrote: July 31st, 2021, 10:22 am I don't suppose Rainmeter has been updated to support this?

EDIT: I found out how to do this via .bat file. But would be a good to know if Rm has had this function added or not.
I know you added the edit but for anyone else who wants the addon here it is attached.

Runs simply:

Code: Select all

LeftMouseUpAction=["#@#TaskKiller.exe" "notepad.exe"]
635 kb executable.
Source inside as well.
Made in AutoIt.
Courtesy of moshi.
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 »

I'll keep that in mind, but I probably won't share any skins after the last time! :oops:
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 »

Active Colors wrote: July 31st, 2021, 1:27 pm I know you added the edit but for anyone else who wants the addon here it is attached.

Runs simply:

Code: Select all

LeftMouseUpAction=["#@#TaskKiller.exe" "notepad.exe"]
635 kb executable.
Source inside as well.
Made in AutoIt.
Courtesy of moshi.
I just don't see any advantage to an external application, written in AutoIt that many antivirus apps hate, to replace something that is just built-into Windows. Likely Moshi wrote this before we had the RunCommand plugin I guess, in order to suppress the display of a command window for a second. I'd vote against this in the current environment.
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, 1:28 pm I'll keep that in mind, but I probably won't share any skins after the last time! :oops:
I would not let anything that happened before discourage you. Feel free to distribute skins as you like. Just give appropriate credit to authors your work uses or is directly based on, and all will be well. You might run into a jerk from time to time who doesn't get that Rainmeter is ALL ABOUT sharing and learning by using other's code, but that's their karma, not yours.
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 »

Ok thank you :welcome:

Tbh though, I think about 80% of my code is copied from others! My Media skin started off with Poiru's work on Soita for example. Then my drives code included in my sidebar skin was mostly done by yourself. Even RecycleBin was mostly copied from Illustro then enhanced through requests on here. I'm just not that good at this coding thing, much as I'd like to be.

The only reason I shared in the past was to pass these ideas on to others, NOT to take credit for it, because I simply can't!

Like the CountdownTimer I'm adapting from Balala's skin, it's his work, even if I am changing it a great deal to suit my way of working and condensing parts, the issues I'm having are just beyond me! But I do try to have a go myself before asking for help as it is quite good fun really, even if a little frustrating at times! :lol: