Jump to content

Turn off monitor when shutdown button pressed from start menu


Recommended Posts

Hi 

i had made a thread before this 

'?do=embed' frameborder='0' data-embedContent>>

it is pretty much the same idea if a moderator is here please delete that 1

i want to make  script that when i open start menu a button shows on top windows shutdown button

when i click the Autoit button a mntroff.exe will be executed 

montroff.exe is a app the turn off the PC monitor

i had tried a lot to find another way to turn off the monitor when the shut down button is presses but with no luck, i tried to interrupt the win 7 shutdown then turn off monitor also with no luck

so now i'm trying this trick but im having some problems on my notepad example: the button was flashing but  working but now (when dealing with start menu) the button is flashing and not working  i think it is because of the start menu it is not like a normal window

 

here is what i tried 

#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>

$GUI = GUICreate("MY GUI", 93,22,267,686, $WS_POPUP , $WS_EX_TOPMOST)
$but = GUICtrlCreateButton("", -1, -1, 500, 500)
guisetstate()



While 1
    $nMsg = GUIGetMsg()
    WinSetOnTop($GUI, "", 1)
    $menu = WinExists("Start menu", "All Programs")
    if $menu = 1 then GUICtrlSetState($but, $GUI_SHOW)
    if $menu = 0 then GUICtrlSetState($but, $GUI_HIDE)
    If $nMsg = $but Then ShellExecute("C:\auto\mntroff.exe")
WEnd

as i said this code is working but not with start menu 

i have no problem if it is flashing but when i press the button the mntroff.exe is not executed

Link to comment
Share on other sites

Is this because your monitor does not automatically shutdown when your PC does?

If that is the case, then you could just write a Shutdown script with a shortcut on your Desktop, that runs mntroff.exe before the shutdown command. You just double-click the shortcut to get both happening, with no need to involve Start Menu at all.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Very difficult for me to reproduce effectively here. You are right that in a lot of cases the start menu is a little bit different to normal windows. Try making the parent of the GUI the start menu, and also look at what styles the start menu has (this can be done from the window info tool, and looking at the bits that are set).

There are several better methods for doing what you want. The best would be to actually get your program to handle the shutdown itself, rather than looking for the button press. Google for examples, there may not be that many in AutoIt, AbortSystemShutdown is the one function you need, either WM_QUERYENDSESSION or WM_ENDSESSION can be used to see if the system is shutting down.

In most cases the best solution would be to use WM_QUERYENDSESSION and return 0 from that, and then turn off the monitor.

Edit: Just tried to shut down with a script running that returned zero from WM_QUERYENDSESSION. It closed down all the applications I had running, including the script itself, but then didn't shutdown. That's just as likely to be windows playing up as the script actually working. I'll experiment a bit more later.

Edited by Mat
Link to comment
Share on other sites

Very difficult for me to reproduce effectively here. You are right that in a lot of cases the start menu is a little bit different to normal windows. Try making the parent of the GUI the start menu, and also look at what styles the start menu has (this can be done from the window info tool, and looking at the bits that are set).

There are several better methods for doing what you want. The best would be to actually get your program to handle the shutdown itself, rather than looking for the button press. Google for examples, there may not be that many in AutoIt, AbortSystemShutdown is the one function you need, either WM_QUERYENDSESSION or WM_ENDSESSION can be used to see if the system is shutting down.

In most cases the best solution would be to use WM_QUERYENDSESSION and return 0 from that, and then turn off the monitor.

Edit: Just tried to shut down with a script running that returned zero from WM_QUERYENDSESSION. It closed down all the applications I had running, including the script itself, but then didn't shutdown. That's just as likely to be windows playing up as the script actually working. I'll experiment a bit more later.

 

bro we had disscussed this here

im finding it so complicated and im new to autoit

please can u just find out what is happening with win 7 start menu ?

Link to comment
Share on other sites

TheSaint

Ok nice idea but i was struggling with this code for 5 hours i cant get it to work please try it on  your PC

i'm getting crazy i want to find why it is not working 

I see no benefit in trying to do it the complex way your are, when a simple shortcut on your desktop is quicker and easier.

In fact, all my PC's use that idea, which is simpler for me, because I don't have a Monitor issue, so I just use a variation of -

C:WindowsSystem32shutdown.exe /s /f /t 9

with a simple shortcut, no script.

Why do you need to use the Start Menu approach?

Have you looked at Shutdown in the Help file?

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

And Mat ought to know, a Cat sat on him once .... but that's another ditty!  :muttley:

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

I would try to scan processes for shutdown.exe, and uppon processexists = true, turn off monitor, haven't tried, not sure it would work.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...