Giter Club home page Giter Club logo

Comments (16)

bcurran3 avatar bcurran3 commented on July 17, 2024 7

I did some preliminary testing and it seems:

Invoke-Command -ComputerName RemotePC -Credential Joe -ScriptBlock {Toast -Text 'Test'}

changed to simply:

Invoke-Command -ComputerName $env:COMPUTERNAME -ScriptBlock {Toast -Text 'Test'}

works.

I first verified by opening up a Command Prompt as SYSTEM. (PsExec.exe -i -s cmd.exe) and used the Invoke-Command above - toast messages appeared to me logged in (obviously not as SYSTEM).

Not completely trusting that, I made a quick scheduled task to run and test:

schtasks /create /TN ToastTest /RU SYSTEM /RL HIGHEST /TR "powershell.exe Invoke-Command -ComputerName $env:COMPUTERNAME -ScriptBlock {Toast -Text 'ToastTest'}" /SC ONCE /ST 20:33 /V1 /Z

..and the toast appeared!

I'm going to implement and test this methodology in my actual scripts (need to do some adjusting to local variables) and will report back.

Joy!

from burnttoast.

jholl016 avatar jholl016 commented on July 17, 2024 1

One possible solution: configure a second scheduled task that launches the toast under the logged in user context, then have your System task trigger the notification task.

from burnttoast.

juststur avatar juststur commented on July 17, 2024 1

Basically how I have it setup now...just messy for documentation/support for others on my team trying to indicate what parts of the process are setup/triggered in what way.

from burnttoast.

bcurran3 avatar bcurran3 commented on July 17, 2024 1

@nmcspadden No, I haven't revisited it yet.

My test above worked but ran into problems when trying to use a button with it. I couldn't get a $button=New-BTButton -Content "blahblah" to work sending it that way to SYSTEM. It would gave an error. I think I just didn't pass the variable correctly. I put it on hold because trying to debug it was driving me nuts. (It was probably the wee hours of the morning).

I plan to split it in two phases now 1> make it work from SYSTEM minus the button which should be super easy as proof of concept has occurred and will revisit very soon. 2> Figure out my error in passing the button variable around. (Hmmmm..... might "cheat" and just assign it as global then remove it. That way I don't have to "pass" it. Hmmmmm) Now I might have to revisit it today!

from burnttoast.

bcurran3 avatar bcurran3 commented on July 17, 2024 1

Actually I still failed previously as none of my variables would pass along. I'd get a toast message across to the logged in user (me!) from the SYSTEM account, but the message would not include the variable info I tried to pass along.

I searched and I searched and found a few Q&As about using Invoke-Command and passing variables. The suggested -ArgumentList (,$arrayname) and using $args[x] failed me as I'd get all the arguments instead of just the one element I wanted. The examples I tried worked, but when I tried them myself... no workie. Finally found one that suggestion using and defining with param().

SUCCESS!

So the short of it for anyone who wants to send toast messages from the system account or other to all users, you can use this example:

(The following was tested by running PsExec.exe -i -s cmd.exe to get a Command Prompt as SYSTEM and then I ran PowerShell.)

powershellexample

toastresult

So my little pet project of https://chocolatey.org/packages/chocolatey-toast-notifications.extension is now where I want it to be. I feel triumphant and happy. So I'll close this issue as it's all working without the need for an enhancement of BurntToast!

from burnttoast.

juststur avatar juststur commented on July 17, 2024

I would make use of such a feature.

from burnttoast.

Windos avatar Windos commented on July 17, 2024

Unfortunately I don't have a "clean" method that I've extensively tested. I need to work on some "official" guidance and am open to suggestions/requests.

The main option I've been playing with are scheduled jobs/tasks running as the user (only when logged in, so you don't need to plug in a password).

It wouldn't work in your use case (and I'm not 100% sure it'd work at all), but you could also drop a script into the user's startup folder... though this then completely hinges on the user logging in fresh at some stage.

from burnttoast.

nmcspadden avatar nmcspadden commented on July 17, 2024

@bcurran3 did your fix get implemented? I'm in a similar situation now where our config management creates the task as SYSTEM but the execution doesn't trigger a notification as-is.

from burnttoast.

nmcspadden avatar nmcspadden commented on July 17, 2024

I'm happy to help test anything.

from burnttoast.

bcurran3 avatar bcurran3 commented on July 17, 2024

OK. I'm still failing. Same problem. Maybe someone smarter than me can tell me what I'm doing wrong...

image

from burnttoast.

bcurran3 avatar bcurran3 commented on July 17, 2024

As far as the proof of concept, works fine when NOT trying to use the -Button parameter.

I'm guessing I need to define or pass it along differently, but I'm too ignorant.

(Keep in mind that below is missing a lot of $env variables and thus displaying blanks.)

image

from burnttoast.

bcurran3 avatar bcurran3 commented on July 17, 2024

Feeling a little smarter now....

SUCCESS!

Invoke-Command -ComputerName $env:COMPUTERNAME -ScriptBlock {New-BurntToastNotification -Text "Chocolatey ($env:chocolateyPackageName)", "$chocolateySoftwareName v$env:chocolateyPackageVersion", "Uninstalled." -Button (New-BTButton -Content 'Package Webpage' -Arguments "https://chocolatey.org/packages/$env:chocolateyPackageName") -AppLogo "$env:ChocolateyInstall\extensions\chocolatey-toast-notifications\choco.ico"}

Moving the New-BTButton creation into a result of part of the full command instead of assigning a variable to it and then passing the variable worked.

@nmcspadden, I retract my "No' answer and now say Yes. :)

...and a hint on use:

COMMENT: check for system account
if ($env:USERNAME -eq "$env:COMPUTERNAME$"){
COMMENT: WinRM needs to be running
If ((Get-Service $WinRM).Status -eq 'Running') {
Invoke-Command -ComputerName $env:COMPUTERNAME -ScriptBlock {blahblah}
}
}
COMMENT: else skip or create toast message without Invoke-Command here...

from burnttoast.

ludovicbernard avatar ludovicbernard commented on July 17, 2024

if we want to send for a specific user in an RDS collection, how can we do, thanks for your remarks

from burnttoast.

bcurran3 avatar bcurran3 commented on July 17, 2024

@ludovicbernard Sorry, I have not tried that and not sure. I'm guessing you'd want to figure out the list of computers in the collection and then loop through them sending each the message.

from burnttoast.

Chirishman avatar Chirishman commented on July 17, 2024

In case anyone was wondering this still works for normal toasts, but if you try it with New-BurntToastShoulderTap you just get an empty toast from the People app, no dancing Alfonso Ribeiro.

from burnttoast.

KlausSGS avatar KlausSGS commented on July 17, 2024

I wonder if this is a feature or a bug that might be fixed by Microsoft at some time.

Starting the command in the SYSTEM context and ending up with a toast in the user context without even selecting the user or session. Seeing this working is a real surprise to me. Other processes will just launch in the SYSTEM context when started that way.

Is anybody aware of some piece of information concerning this behavior?

from burnttoast.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.