j0kky

Abort started shutdown - Windows 7

15 posts in this topic

#1 ·  Posted (edited)

Hi,

I'm trying to abort a started shutdown via start>>"Shut Down" on Windows 7 with but I can't find a solution.

It's simple to abort a timed-out shutdown thanks to "shutdown -a" or "AbortSystemShutdown" because (I think) that function only interrupt the timeout.

I've written this simple script (looking to previous posts about this argument): it is an idle loop that waits for WM_QUERYENDSESSION message and then it creates a block reason to stop the shutdown process. But an endless serie of error "the application was unable to start correctly (0xc0000142)" labelled "shutdown.exe" is shown and the shutdown is only paused, not aborted.

#Include <ButtonConstants.au3>
#Include <GUIConstantsEx.au3>
#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

Global $hForm, $Msg, $Button, $Check, $var = False

$hForm = GUICreate('MyGUI', 200, 200)
GUIRegisterMsg(0x0011, 'WM_QUERYENDSESSION')
GUISetState(@SW_HIDE)

_WinAPI_SetProcessShutdownParameters(0x03FF)

While 1
    $Msg = GUIGetMsg()
    _WinAPI_ShutdownBlockReasonCreate($hForm, 'something')
    If $var = True Then Run("C:\windows\system32\shutdown.exe -a")
WEnd

Func WM_QUERYENDSESSION($hWnd, $Msg, $wParam, $lParam)
    Switch $hWnd
        Case $hForm
            $var = True
            Return 0
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_QUERYENDSESSION

I'm beginning to think that what I want to do is impossible :(

Thanks to all. 

Edited by j0kky

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

My family use my laptop and then they use to shutdown pc causing problems to execution of Vuze, BOINC, and other programs... So I would like to intercept ShutDown and convert it to Sleep.

Edited by j0kky

Share this post


Link to post
Share on other sites

Thank you for the answer!

With Sleep you can resume works where you have suspend them:

 

[...]sleep puts your work and settings in memory and draws a small amount of power[...]

 

I've solved changing the default ShutDown button on start menu with Sleep but it is a sort of palliative.

Is there a way to automatically abort the shutdown with a script?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Probably, but I imagine it's a rather advanced and complicated endeavor.

Probably have more chance searching web for such a function before someone here takes it on.

Ok it's what you want. but if it were me it would not be worth the trouble, because I'd simply lock my laptop if other users did not respect my wishes not to shut it down.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

This is a good solution... but not for me: I keep the laptop always on, logged in my account.

I'm not worried about the programming endeavor but I've gone over shutdown references on MSDN and it seems there is no functions good for this purpose.

Do you have any ideas?

Edited by j0kky

Share this post


Link to post
Share on other sites

Install HandyCafe, you can't shut down a computer if the client is running

Share this post


Link to post
Share on other sites

So, you want your laptop available on demand, applications that are running to stay running, and keep your family from shutting down the laptop.

Why not just get them their own laptop and your problem is solved permanently? They can shut down to their heart's content, your stuff is not messed with at all and you don't need to worry about "custom" settings on your laptop. 

Share this post


Link to post
Share on other sites

ahahah, a bit too expensive solution  :sweating: 

Joking apart, I've red these "best practice" form MSDN:

 

  • Applications should not block shutdown. Respond to WM_QUERYENDSESSION as quickly as possible and postpone cleanup activities until processing the WM_ENDSESSION message.
  • Applications that must block shutdown should use the new ShutdownBlockReasonCreate function to register a string that explains the reason to the user. The user can decide whether to continue or cancel shutdown.
  • Applications cannot rely on being able to block shutdown.

 

They don't tell us we can't do what I want, they tell us we just shouldn't... However they don't provide a direct function to abort the started shutdown  :ermm: 

Share this post


Link to post
Share on other sites

How about this - setup separate profiles. The other profiles have the shutdown option revoked. Your profile is password protected. This is NO money to do, they don't mess with anything you have running on your profile and you don't mess with anything they have. Nice, simple, free, and no scripting needed.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

A small question:

Why do you loop

_WinAPI_ShutdownBlockReasonCreate($hForm, 'something')

a gazillion times? It needs to be called once only.

Edited by Unc3nZureD

Share this post


Link to post
Share on other sites

@Unc3nZureD: You're right, I've included it in the called function.

@MBALZESHARI: I have Windows 7 home premium and it hasn't Group Policy editor (Local Security Police snap-in)  : 

Share this post


Link to post
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