Quantcast
Channel: Rainmeter Forums
Viewing all articles
Browse latest Browse all 482

Execute PowerShell script with MouseClick

$
0
0
I am trying to make a button to restart the PC but with additional confirmation. I have made a simple Powershell script that does exactly that. One way to do it would be to link the click action to a shortcut pointing to the ps1 file, but in my opinion that's not ideal. I found a plugin that allows me to write and execute a PowerShell script directly in Rainmeter, but I have some issues.

This is a snippet of the current code:

Code:

[PSRM]Measure = PluginPlugin = PowershellRMLine  = Add-Type -AssemblyName System.Windows.FormsLine2 = $result = [System.Windows.Forms.MessageBox]::Show("Do you want to restart the PC?", "Restart Confirmation", [System.Windows.Forms.MessageBoxButtons]::YesNo, [System.Windows.Forms.MessageBoxIcon]::Question)Line3 = if ($result -eq [System.Windows.Forms.DialogResult]::Yes) {Line4 = Restart-Computer -ForceLine5 = } else {Line6 = }[MeterRestart]Meter=ImageImageName=#@#Icons\restart.pngImageTint=#Lavender#X=90Y=20H=40W=40AntiAlias=1LeftMouseDoubleClickAction=[!CommandMeasure PSRM "Run"]
The issue is that script gets executed directly on loading or refreshing the skin and constantly loops until Rainmeter crashes. I clearly did something wrong here. I want the script to only execute when double clicking said skin.

Statistics: Posted by conaN — Yesterday, 3:07 pm — Replies 2 — Views 82



Viewing all articles
Browse latest Browse all 482

Trending Articles