Sign in to follow this  
Followers 0
Briegel

function to forbid systemshutdown

24 posts in this topic

All the time my script is working (backup) I don't want the local user to shutdown or restart the system. How can I forbid the systemshutdown? I know our software distributing system can do so.

I searched this forum for a while and only found one post from VicTT but without a solution.

Quote VicTT:

Global $WM_QUERYENDSESSION=0x0011

Func InterceptShutdown($hWnd,$msg,$w,$l)

MsgBox(0,"","Shutting down")

EndFunc

GUIRegisterMsg($WM_QUERYENDSESSION,"InterceptShutdown")

while 1

wend

Can this quote help?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

All the time my script is working (backup) I don't want the local user to shutdown or restart the system. How can I forbid the systemshutdown? I know our software distributing system can do so.

I searched this forum for a while and only found one post from VicTT but without a solution.

Quote VicTT:

Can this quote help?

all I can think of is that you run a script that detects when the shutdown button or restart button is press then send to the command prompt: "shutdown -a" to abort the shutdown...

or... look at local group policy's to see if their is a switch to turn off logoff and shutdown.

Edited by gleem

Share this post


Link to post
Share on other sites

@gleem,

thanks for helping.

I think there's no way to identify the shutdown button (or only I can't).

To use GPO's it's not the solution I prefer. I know there is a way by using a function with '$WM_QUERYENDSESSION'. But who in this forum is able to solve this problem?

Share this post


Link to post
Share on other sites

But wouldnt someone be able to shutdown whatever you try?

I thought, holding down the "off" button, for 5 seconds, was the "Safe" shutdown, liek, when your computer freezes and stuff. That would still be active, no?


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

@AzKay,

a user who holds down the power on/off during backup has no reason for crying :D

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Well if it's just the Log off screen your looking at, after play with Windows XP Pro this worked:

While 1
    If _CheckForShutDown() Then MsgBox(64, 'Info', 'Shut down was aborted.' & @CR & 'Please wait for the setup to finish.')
    Sleep(10)
WEnd
Func _CheckForShutDown()
    Local $sWin = WinGetHandle(''), $iCountButtons = 0
    Local $aButtons[4] = ['Button1', 'Button2', 'Button3', 'Button4']
    Local $aButtonNames[4] = ['Cancel', '&Stand By', 'T&urn Off', '&Restart']
    For $iCount = 0 To 3
        If ControlCommand($sWin, $aButtons[$iCount], $aButtonNames[$iCount], 'IsVisible', '') Then
            $iCountButtons += 1
        EndIf
    Next
    If $iCountButtons = 4 Then 
        ControlClick($sWin, 'Cancel', 'Button1')
        Return 1
    EndIf
    Return 0
EndFunc
Generic, but at least an answer you didn't have.

Edit:

Typo

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Generic, but at least an answer you didn't have.

@SmOke_N,

you're not right. I have the same answer: NO SOLUTION

I admit that I'm too smallish to understand your script. So I started it and ...

shutdown my system (XP Pro).

I was reading a lot of your (great) answers in this forum and so I don't think it's one of your jokes. Or?

Share this post


Link to post
Share on other sites

@SmOke_N,

you're not right. I have the same answer: NO SOLUTION

I admit that I'm too smallish to understand your script. So I started it and ...

shutdown my system (XP Pro).

I was reading a lot of your (great) answers in this forum and so I don't think it's one of your jokes. Or?

It's not a joke, it only clicks the cancel button, now it doesn't do anything with Ctrl+Alt+Delete twice, it's only effective when the user does: Start >> Turn Off Computer, it will press cancel and give the pop up.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

@SmOke_N,

thanks for helping and your explanation. Now I understand. I've a german XP and so I translate '$aButtonNames'. Unfornately the script doesn't work. But the idea is right.

This works:

While 1
If WinActive ("Windows herunterfahren","Beendet die Sitzung") = 1 Then
    ControlClick ("Windows herunterfahren","Beendet die Sitzung","Button4")
    MsgBox(16,"Herunterfahen nicht erlaubt","Während des Backups darf der PC nicht heruntergefahren werden!")
EndIf
WEnd

With this I'm able to realize what I want.

But there's no limit to my ambition. There must be a solution using 'DllCall'. Where are the developers from this forum? This feature would be a great enhancement for AutoIt!!!

Share this post


Link to post
Share on other sites

What I used to do a long time ago is to write a batch script (something) like this:

asdf:
shutdown -a
goto asdf
in order to prevent shutdown.

However, this solution eats up a lot of CPU.

maybe try this?:

while 1
   Sleep(10)
   Run(@ComSpec & " /C shutdown -a")
wend

#)

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

@SmOke_N,

thanks for helping and your explanation. Now I understand. I've a german XP and so I translate '$aButtonNames'. Unfornately the script doesn't work. But the idea is right.

This works:

While 1
If WinActive ("Windows herunterfahren","Beendet die Sitzung") = 1 Then
    ControlClick ("Windows herunterfahren","Beendet die Sitzung","Button4")
    MsgBox(16,"Herunterfahen nicht erlaubt","Während des Backups darf der PC nicht heruntergefahren werden!")
EndIf
WEnd

With this I'm able to realize what I want.

But there's no limit to my ambition. There must be a solution using 'DllCall'. Where are the developers from this forum? This feature would be a great enhancement for AutoIt!!!

Guess you could try this and a mixture of what everyone is saying with shutdown -a
While 1
    If _CheckForShutDown() Then MsgBox(64, 'Info', 'Shut down was aborted.' & @CR & 'Please wait for the setup to finish.')
    Sleep(10)
WEnd
    
Func _CheckForShutDown()
    Local $sWin = WinGetHandle(''), $iCountButtons = 0
    Local $aButtons[4] = [2, 20104, 20103, 20105]
    For $iCount = 0 To 3
        If ControlCommand($sWin, '', $aButtons[$iCount], 'IsVisible', '') Then
            $iCountButtons += 1
        EndIf
    Next
    If $iCountButtons = 4 Then 
        Run(@ComSpec & ' /c shutdown -a', '', @SW_HIDE)
        Return 1
    EndIf
    Return 0
EndFunc
That way it could be called with AdlibEnable() or something.

Edit:

Hmm, I kept posting the wrong code... I need a beer :D

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

@nfwu,

up to 50% CPU usage rate is too much and it doesn't work if you choose 'Start - Shutdown/Logoff etc'.

@SmOke_N,

did you really test your script with XP Pro? It doesn't work on my system. Where can I find Buttons 2, 20104, 20103 and 20105? If I choose 'Start - Shutdown' I only can find 'Button4' in the coming window. The 'OK' button kills 'AutoIt Window Info' and the last button is the help button.

So this works for this case:

While 1
If WinActive ("Windows herunterfahren","Beendet die Sitzung") = 1 Then
; i try to translate: WinActive ("Windows shutdown","finished/terminated session")
    ControlClick ("Windows herunterfahren","Beendet die Sitzung","Button4")
    MsgBox(16,"Herunterfahen nicht erlaubt","Während des Backups darf der PC nicht heruntergefahren werden!")
EndIf
WEnd

But what can I do if local user press 'Ctrl - Alt - Del'?

And what can i do if local user use 'shutdown.exe'?

Shooting with 'shutdown.exe -a' isn't acceptable because CPU usage rate is up to 50%.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

I'm on XP Pro Corp.

  • My Steps to shut down:

    a.) Start

    b.) "Turn Off Computer" (could be a language thing, I don't know)

    c.) There are 4 buttons: Stand By|Turn Off|Restart|Cancel

On the other hand... you could always use AdlibEnable() to do what you wanted, but I don't know about the popup your getting, a AutoInfo Tool paste or screen shot would help there.
AdlibEnable('_FinishInstall')

While 1
    ;Do all you need to do
    Sleep(10000)
WEnd

Func _FinishInstall()
    ;Whatever special you want to put here.
EndFunc
But a combination of what your doing, and what I'm saying originally probably would.

Edit:

And not saying that I know, but If I did know how to get around Ctrl+Alt+Del / or ShutDown.exe, I wouldn't post that on the forum anyway.

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

@SmOke_N,

so this works.

; title and text from coming window after clicking 'Start-Power Off' or 'Start-Shutdown' I don't know in englich version
$PowerOffTitle = 'Windows herunterfahren'
$PowerOffText = 'Wie möchten Sie vorgehen'

; title and text from coming input-window after clicking 'Start-Execute?' or pressing {LWin}{R}
$ExecuteTitle = 'Ausführen'
$ExecuteText = 'Geben Sie den Namen eines Programms'

AdlibEnable ('_ForbidShutdown',50)

While 1
    ; do what you want
    Sleep ( 10000)
WEnd

Func _ForbidShutdown()
    ; close windows as mentioned above
    If WinActive ($PowerOffTitle,$PowerOffText) = 1 Then WinClose ($PowerOffTitle,$PowerOffText)
    If WinActive ($ExecuteTitle,$ExecuteText) = 1 Then WinClose ($ExecuteTitle,$ExecuteText)
    
    ; don't be able to run shutdown.exe using command line
    If ProcessExists ("cmd.exe") > 0 Then ProcessClose ('cmd.exe')
    
    ; don't be able to kill any process (AutoIt script) with taskmanager
    If ProcessExists ("taskmgr.exe") > 0 Then ProcessClose ('taskmgr.exe')
EndFunc

There's still one more question:

How to disable pressing 'Ctrl-Alt-Del'?

_IsPressed() only works with 'Ctrl-Alt'. And which action should be done to close coming window after pressing 'Ctrl-Alt-Del'? How can I identify and perhaps close this window?

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

@SmOke_N,

so this works.

; title and text from coming window after clicking 'Start-Power Off' or 'Start-Shutdown' I don't know in englich version
$PowerOffTitle = 'Windows herunterfahren'
$PowerOffText = 'Wie möchten Sie vorgehen'

; title and text from coming input-window after clicking 'Start-Execute?' or pressing {LWin}{R}
$ExecuteTitle = 'Ausführen'
$ExecuteText = 'Geben Sie den Namen eines Programms'

AdlibEnable ('_ForbidShutdown',50)

While 1
    ; do what you want
    Sleep ( 10000)
WEnd

Func _ForbidShutdown()
    ; close windows as mentioned above
    If WinActive ($PowerOffTitle,$PowerOffText) = 1 Then WinClose ($PowerOffTitle,$PowerOffText)
    If WinActive ($ExecuteTitle,$ExecuteText) = 1 Then WinClose ($ExecuteTitle,$ExecuteText)
    
    ; don't be able to run shutdown.exe using command line
    If ProcessExists ("cmd.exe") > 0 Then ProcessClose ('cmd.exe')
    
    ; don't be able to kill any process (AutoIt script) with taskmanager
    If ProcessExists ("taskmgr.exe") > 0 Then ProcessClose ('taskmgr.exe')
EndFunc
oÝ÷ Ù8^­íý²ËbZ'zj+z«²Ø¨z0¶b±¦åz޲ȧB¶¹@ÐÞH°ú޲ǢyrÂä³­B¶¹@Ýýwp'!iËb¢{!¢é]mçhëhrZ,&x0whÁ§ízºkzË"
ý
Úå[Cz]ýjr"uéíüÚ^®©±Éh±ëaÌ"Ú0þ«¨µäázÉÞjL©zx.|!Ê^®Ë!ûrjëh×6If RegWrite("HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", "DisableTaskMgr", "REG_DWORD", 1) Then
     MsgBox(64, "Evil Laugh...", "Try to escape with your puny Ctrl+Alt+Del now!  BwaHaHaHa!!!")
Else
     MsgBox(16, "Error!", "Error setting registry to disable Ctrl+Alt+Del")
EndIf
Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

If the sneaky penguin whispers...then

the Briegel ist listening

EndIf

So this is approximately what I want. Local user has less chances to shutdown the system during system backup.

Opt('OnExitFunc', 'endscript')

; title and text from coming window after pressing 'Start-Shut Down' 
$PowerOffTitle = 'Windows herunterfahren'
$PowerOffText = 'Wie möchten Sie vorgehen'

; title and text from coming input-window after clicking 'Start-Run' or pressing {LWin}{R}
$ExecuteTitle = 'Ausführen'
$ExecuteText = 'Geben Sie den Namen eines Programms'

; don't be able to log off
RegWrite ('HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer','NoLogOff','REG_DWORD', 1)

; don't be able to shut down
RegWrite ('HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer','NoClose','REG_DWORD', 1)

AdlibEnable ('_ForbidShutdown',50)

While 1
    ; do what you want
    Sleep ( 10000)
WEnd

Func _ForbidShutdown()
    ; close windows as mentioned above
    If WinActive ($PowerOffTitle,$PowerOffText) = 1 Then WinClose ($PowerOffTitle,$PowerOffText)
    If WinActive ($ExecuteTitle,$ExecuteText) = 1 Then WinClose ($ExecuteTitle,$ExecuteText)
    
    ; don't be able to run taskkill.exe or shutdown.exe using command line
    If ProcessExists ('cmd.exe') > 0 Then ProcessClose ('cmd.exe')
    
    ; don't be able to kill any process (AutoIt script) with taskmanager
    If ProcessExists ('taskmgr.exe') > 0 Then ProcessClose ('taskmgr.exe')
EndFunc
    
Func endscript()
    ; be able to log off
    RegDelete ('HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer','NoLogOff')
    ; be able to shut down
    RegDelete ('HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer','NoClose')
EndFunc
    
Exit

Thanks for all helping ideas.

Briegel

Share this post


Link to post
Share on other sites

i think i have a WAY easyer solution for u XD

goto config, then system manage (where u change the services)

then goto local secureysettings (a computer with a lock)

in there, goto local (something like that)

then the 2nd from the top

there u have it a list with what a user can, or can't do

system shutdown is one of them :D this way u can change this to make the user unable to shutdown

p.s. sorry for my strange explanation, but my XP pro is in dutch :wacko:


*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...

Share this post


Link to post
Share on other sites

lol, when you do that, the only way to bypass it is by pulling out the plug :D


Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Share this post


Link to post
Share on other sites

I only want to limit the local user during system backup without any reboot before or after this process. My script is running with user rights and so the possibilities are limited. In my opinion my script is a good compromise.

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

I'm pretty sure you could make your own Group Policy scripts and forbid user shutdowns, but I'm really busy and can't find it right now

start>run "gpedit.msc"

xp pro users only

EDIT: You could just run the script, then logoff and use this.

Posted Image

Edited by gamepin126

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
Sign in to follow this  
Followers 0