Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

User Image
Watchful1
5 discussion posts
I have some Phillips Hue lights behind my desk that I want to turn off when my computer turns off, and turn on when it turns on. I've set up IFTTT to turn them on and off when it receives a specific GET request, but I'm having a very tough time getting anything to run when I shutdown. I thought of trying DisplayFusion since it has custom scripting and trigger functions. I wrote a quick script to send the GET request, which works, and set it up with the "DisplayFusion Exits" trigger. It works when I manually exit DisplayFusion, but it does not run when I shutdown my computer.

Is it possible to do this with DisplayFusion?
Aug 12, 2018  • #1
User Image
Kevin F.
450 discussion posts
You could use triggers to watch a different process that always ends before df, but that may not be consistent.... Maybe you can watch for shutdown.exe to be created?

A much better option is probably using the actual scripting languages though, C# and VB surely have an answer. I already found a shutdown after 15 seconds function, should be minimal work to edit that to be shorter and send your get? (I don't really code)

Just realized you probably used the script already, forgot you could tie that into triggers. Just make/mod the whole script for the shutdown and make a keybind imo.
Aug 13, 2018 (modified Aug 13, 2018)  • #2
User Image
Watchful1
5 discussion posts
I don't think shutdown.exe is run every time windows shuts down. It's just one way to trigger shutdown.

It would be trivial to write a script, either using displayfusion or just a batch script, to send the web request and then shutdown. But I want to instead have a script run automatically every time the computer turns off. Whether by pressing the hardware power button, or clicking shutdown in the start menu.

I was hoping the "DisplayFusion Exits" trigger would run when the program shuts down as the computer turns off, but it's looking like that's not the case.
Aug 14, 2018  • #3
User Image
AlainCh2
90 discussion posts
Look if it may be of any help.

I have create a blank shortcut on my desktop, renamed "Sleep.it", connected to Ctrl+Shift+Z,
and (inside it) inserted several chained PowerShell commands...
the last one is:

Code

%windir%\System32\rundll32.exe powrprof.dll,SetSuspendState Standby


I'm using it (instead of SleepButton/Start>>Sleep) to ensure proper actions any time I leave my desktop.

May be it would do if you use a similar solution to shutdown your PC instead of using PowerButton.

Cons: you may remember it only after you pushed the Button :-)

Alain
• Attachment: Capture.JPG [46,620 bytes]
Capture.JPG
Capture.JPG
Aug 14, 2018 (modified Aug 14, 2018)  • #4
User Image
Kevin F.
450 discussion posts
Quote:
I don't think shutdown.exe is run every time windows shuts down. It's just one way to trigger shutdown.

It would be trivial to write a script, either using displayfusion or just a batch script, to send the web request and then shutdown. But I want to instead have a script run automatically every time the computer turns off. Whether by pressing the hardware power button, or clicking shutdown in the start menu.

I was hoping the "DisplayFusion Exits" trigger would run when the program shuts down as the computer turns off, but it's looking like that's not the case.


This would be a shortcut on desktop maybe or just a context menu option my way but yea... troublesome.
Aug 14, 2018  • #5
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Having the "DisplayFusion Exits" trigger rules run on shutdown doesn't really work, because Windows won't wait for the stuff to run, and we can't really block shutdown because if you're executing an external command, DisplayFusion has no idea if/when it finished :(

However, if you're running Windows 10 Pro, you could use a Shutdown or Log Off Script to do what you're looking for. If you're running Windows 10 Pro, try this:

  • Open a Run prompt, type gpedit.msc and click OK
  • Expand Computer Configuration > Windows Settings, and select Scripts (Startup/Shutdown)
  • Double-click Shutdown in the right-pane
  • Click Add, and add a batch file that does your stuff
  • Test it out

Hope that helps!
Aug 14, 2018  • #6
User Image
Watchful1
5 discussion posts
Unfortunately I have Windows 10 home and I don't really want to spend a hundred dollars to upgrade just for this. I've tried every solution I could find, but I can't get the group policy editor to run shutdown or logoff scripts.

Do you know if DisplayFusion tries to run the trigger when it shuts down due to the computer shutting off and just gets interrupted? Or does it not try at all? Making my one network call is very fast and I would be hopeful it could run in the half second while windows finishes closing programs.
Aug 15, 2018  • #7
User Image
AlainCh2
90 discussion posts
A question :
HOW do you shut down your computer?

Power Button
>Start>Shutdown
BAT file ?

Alain
Aug 15, 2018  • #8
User Image
Watchful1
5 discussion posts
I'm looking for a solution that will work both for pressing the power button and start->shutdown.
Aug 15, 2018  • #9
User Image
AlainCh2
90 discussion posts
I'm afraid there will be only one:
A shortcut tied with any keys combination like CTRL+SHIFT+S.

It allow you to run your script or any program you like,
then call "shutdown /s /f /t 0" to close all operations.

If you don't need to use any "start" command,
the sequential execution will ensure that all instances will run properly before shutting down.

_________ copy ___________________________________________ a) __
Chain command since 2000, and still good today:

Code

Dir & Echo too

(before it was the "|" pipe)

If you want the second command to execute only if the first exited successfully:

Code

Dir && Echo too


(that ensure you'll shutdown only if preceding instances was successful)

But if you need to pass variable between one command and the others...
>>Delayed Expansion feature only available in batch files BAT, CMD:<<
Ex:

Code

setlocal EnableDelayedExpansion && set MyVar=MyVal && echo !MyVar! && endlocal

(NOTE: The feature requires you to use ! marks in place of the % symbols.)
________________________ end copy ______________________

For what I know Windows has no way to recognized itself any instance to run BEFORE closing operations, unless using Group Policy.

But out of Windows you can try this with AutoHotKey

_______ copy____________________________________ b) _____

I made a basic batch file that will create a "test file" on the desktop. Just run the AHK file and leave it running. When the script detects a shutdown, it'll run the batch file.
This script is tested and working.
Make sure you set the path to your text file at the top of the script.

AutoHotkey Script:

Code

;==============================
;Set the path to your batch file.
path    := "C:\batch.bat"
;==============================

; Run script as admin. This will allow your batch file to be ran with admin priv.
if not A_IsAdmin
{
   Run *RunAs "%A_ScriptFullPath%"  ; Requires v1.0.92.01+
   ExitApp
}

; Only allow one instance of the script to run.
#SingleInstance, Force

; If you don't want an icon to show in the tray,
; remove the semicolon from the line below.
;#NoTrayIcon

; When script detects WM_QUERYENDSESSION (a shutdown), run OnShutDown function.
OnMessage(0x11, "OnShutDown")
return

OnShutDown(){
    ; Run the batch file.
    Run, % path
    ExitApp
}


Batch file I used for testing:

Code

echo Write file before shutdown > %USERPROFILE%\Desktop\ShutdownTest.txt

If you wanted to, you could always execute your batch file commands directly through AHK.

_________________________end copy ___________________

I stumbled upon this question myself time ago, it was easy to recover my findings.

I Hope you'll find that useful.
( for myself I use BAT and ShortCuts )

Alain

References:
a) http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds_shelloverview.mspx?mfr=true

b) https://superuser.com/questions/1202064/how-do-i-run-a-batch-script-at-shutdown-in-windows-10-home-edition
Aug 15, 2018 (modified Aug 15, 2018)  • #10
PabloMartinez's profile on WallpaperFusion.com
As for me, it is easier to write a service. If you know Python well, then I think it will be easy to understand C#. Moreover, there is no need for something complex. Some help for understanding can be seen here: https://docs.microsoft.com/en-us/dotnet/framework/windows-services/walkthrough-creating-a-windows-service-application-in-the-component-designer
Sample pseudocode:

Code

public TestService()
{
    InitializeComponent();
    CanShutdown = true;
}

protected override void OnStart(string[] args)
{
    try
    {
        YourRequestMethod(true);
    }
    catch (Exception ex)
    {
        System.Windows.Forms.MessageBox.Show(ex.Message);
    }
}

protected override void OnShutdown()
{
    try
    {
        YourRequestMethod(false);
    }
    catch (Exception ex)
    {
         System.Windows.Forms.MessageBox.Show(ex.Message);
    }
    base.OnShutdown();
}

private static void YourRequestMethod(bool flag)
{
    if(flag)
    {
        // Your GET request to ON
    }
    else
    {
        // Your GET request to OFF
    }
}
Aug 15, 2018  • #11
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(-)  Login to Vote(-)