System Tray Icon One-Liners

Is anybody else up to sharing their System Tray Icon-compatible one-liner commands?

I’ll start!

powershell.exe -command "$exePath = '\\SOMESERVER\FOLDER\Setup.exe'; $instName = 'LOB Application Name'; Add-Type -AssemblyName PresentationFramework; if (Test-Path -Path $exePath) { $res = ([System.Windows.MessageBox]::Show(('Are you ready to install ' + $instName + '? (Note: It may take a moment for the installer to download and launch.)'),'Automated Installer',1,32)); if ($res -eq 'OK') {Start-Process $exePath} } else { [System.Windows.MessageBox]::Show('PC must be connected to work network to install.','Automated Installer - ERROR',0,16) }"

This command will allow an application to be installed from the Syncro System Tray icon and includes a user confirmation prompt, a test for the file as well as a notice to be patient. It’s easily adapted by changing the two variables at the beginning of the command: exePath and instName. Stick it in the policy’s System Tray as a “Execute a CMD” type and away you go.

5 Likes

Here’s another that clears the Microsoft Teams cache and seems to fix about 90% of calls about Teams acting up. (Or don’t get any more because users can self-medicate.)

powershell.exe -command "Get-Process Teams | stop-process -force; Start-Sleep -Milliseconds 1500; Remove-Item -path $env:APPDATA'\Microsoft\teams\Cache\*'; Remove-Item -path $env:APPDATA'\Microsoft\teams\blob_storage\*'; Remove-Item -path $env:APPDATA'\Microsoft\teams\databases\*'; Remove-Item -path $env:APPDATA'\Microsoft\teams\GPUcache\*'; Remove-Item -path $env:APPDATA'\Microsoft\teams\IndexedDB\*' -recurse; Remove-Item -path $env:APPDATA'\Microsoft\teams\Local Storage\*' -recurse; Remove-Item -path $env:APPDATA'\Microsoft\teams\tmp\*'; Start-Sleep -Milliseconds 1500; Start-Process -FilePath $env:LOCALAPPDATA'\Microsoft\Teams\Update.exe' -ArgumentList '-processStart Teams.exe'"

Clears printer queue, I may have grabbed this from somewhere.

powershell "Stop-Service spooler -Force; $files = Get-ChildItem -Path $env:SystemRoot\System32\spool\PRINTERS -Force; $files | Remove-Item -Force; Start-Service spooler;[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms');[System.Windows.Forms.Messagebox]::Show('Print queue cleared!')"
2 Likes

Simple ones

3 Likes

A very nice one. I can see use for that for sure!

Neat! How have you done to add the little icon next to the title? I mean I guess it’s a copy/paste but, is there somewhere we can see all icon available?

Thanks!

Win + period will bring up the emoji menu and just copy and paste. Not Syncro specific, just uses what’s available in Windows.

I got the values from this page: How to show a message box with windows powershell

I swapped-in the Integers to keep things short.

Force Close All Browsers & prevent recovery button from working

powershell "Stop-Process -processname chrome,iexplore,firefox,msedge;Start-Sleep -Second 3;Remove-Item "$ENV:HOMEDRIVE\Users\*\AppData\Local\Google\Chrome\Userda~1\Default\Sessions" -Recurse -Force;Remove-Item "$ENV:HOMEDRIVE\Users\*\AppData\Local\Microsoft\Edge\Userda~1\Default\Sessions" -Recurse -Force;Remove-Item "$ENV:HOMEDRIVE\Users\*\AppData\Roaming\Mozilla\Firefox\Profiles\*\sessionstore-backups\recovery.jsonlz4" -Force;[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms');[System.Windows.Forms.Messagebox]::Show('Browsers closed!')"

Okay, this is slick! What a great option for those people with the “RED BOX OF BEEP AND WARNING” problems… (What web sites do they browse anyway?)

Quick question… Do the embedded double-quotes create any issues as a “one-liner” or would they be better swapped out with single-quotes?

Yes, that’s exactly the intention. IME it’s usually Facebook right before in their browser history so I’m guess advertisements that either manage to redirect or they actually clicked on.

The double-quotes are required if you want to use variables within them (ENV in this case) but otherwise yes they could be replaced by singles. Believe me there were a few iterations to get it to work :smiley: Had to use 8.3 folder name to get avoid the spaces causing an issue also.

1 Like

Or recipe sites around any holiday…

It would be really nice to run a script from the library from the tray. Then the script runs would be logged and have access to Syncro Customer and Asset variables.

Some nice scripts in here so far. Please keep them coming.

1 Like

For sure. I have a little side-project (Shhhhh. don’t tell Syncro!) to load their modules and try to back-fill all of the connection details but so far am blocked by security… (Good thing… I guess.) :crazy_face:

Yea, I’ve been asking for this for years. They don’t want to do it for some reason.

1 Like

These are handy but it would be a LOT better to just be able to present select scripts the user can run.

These scripts are easier to maintain and you have one location for maintaining them rather than having some duplication. The scripts are also more powerful with variables and calls to Syncro functions like logging and alerts…

2 Likes

They can run scripts from the Customer Portal. It’s not as easily accessible as the tray icon but it is an option. The downside is the script ends up being available on every customer portal (unless you restrict them from scripts via permissions.)

I wonder if there are security implications with this that would make it unsafe? #thinkingoutloud

We understand that we can have scripts for all portal users, but that’s not feasible when you have many clients that each have scripts that would work great for them, and totally not at all for others.

Essentially, add a new try option for Scripts, Set the option name (same as we do with CMD) then have a dropdown of scripts (as we do on an asset queue), then add the selected script to the asset’s script queue, maybe with an option for a toaster notification after that says “action requested” or whatever.

Take any powershell script. It doesn’t have to be a 1-liner. Then surround it with the following code:

$code = {
	#Put your code here
	rundll32.exe user32.dll,LockWorkStation
}
[convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($code))

Then it will output a 64-digit encoded string.

Use the one-liner string as follows (This string is a popup that shows your hostname):

powershell -EncodedCommand DQAKAAkAJAB3AHMAaABlAGwAbAAgAD0AIABOAGUAdwAtAE8AYgBqAGUAYwB0ACAALQBDAG8AbQBPAGIAagBlAGMAdAAgAFcAcwBjAHIAaQBwAHQALgBTAGgAZQBsAGwADQAKAAkAJAB3AHMAaABlAGwAbAAuAFAAbwBwAHUAcAAoACIAWQBvAHUAcgAgAGMAbwBtAHAAdQB0AGUAcgAgAG4AYQBtAGUAIABpAHMAOgAgACIAIAArACAAIAAkAGUAbgB2ADoAYwBvAG0AcAB1AHQAZQByAG4AYQBtAGUALAAwACwAIgBDAG8AbQBwAHUAdABlAHIAIABOAGEAbQBlACIALAAwAHgAMAApAA0ACgA=

You have successfully converted a full script to a 1-liner for the tray icon.

12 Likes