Jump to content

_ShutDown (UDF)


AutoItKing
 Share

Recommended Posts

Not bad, it's a lot shorter I must say. And I like the reboot.

Thanks, I modify method 4- close all windows except for $sd_leaveopen, remove the limit of keeping only 3 windows open. Now you can keep open as many windows you want. All you need is a string with the titles of all the windows you want to keep open, separeted by pipe |.

Ex:

$Windows = "AutoIt Help|Welcome - Lotus Notes|Untitled - Notepad|untitled - Paint|Remote Desktop Connection"

_ShutDown(4, $Windows)

;===============================================================================
;
; Description:      Close all windows according to $sd_method
; Syntax:           _ShutDown($sd_method, $sd_leaveopen, $sd_leaveopen2, $sd_leaveopen3)
; Parameter(s):     $sd_method - =====================================================
;                                method 0- close all windows and log off
;                                method 1- close all windows and shutdown
;                                method 2- close all windows and reboot
;                                method 3- close all windows
;                                method 4- close all windows except for $sd_leaveopen
;                                =====================================================
;                   $sd_leaveopen - "Window Title"
;                   $sd_leaveopen2 - "Window Title"
;                   $sd_leaveopen - "Window Title"
;
; Requirement(s):   $sd_method
; Return Value(s):  On Success - None
;                   On Failure - None
; Author(s):        AutoItKing <bendudefu [at] aim [dot] com>
; Note(s):          Use with caution!
;
;===============================================================================

Func _ShutDown($sd_method, $sd_leaveopen = "Program Manager")
    $i = 1
    If Not IsArray($sd_leaveopen) Then $sd_leaveopen = StringSplit($sd_leaveopen, '|')
    $sd_windows = WinList()
    While 1
        $Close = True
        If $sd_windows[$i][0] <> "" AND BitAnd( WinGetState($sd_windows[$i][1]), 2 ) AND $sd_windows[$i][0] <> "Program Manager" Then
            If $sd_method == 4 Then
                For $x = 1 To $sd_leaveopen[0]
                    If StringInStr($sd_windows[$i][0], $sd_leaveopen[$x]) <> 0 Then $Close = False                  
                Next
                If $Close Then WinClose($sd_windows[$i][0])
            Else 
                WinClose($sd_windows[$i][0])
            EndIf
        EndIf
        $i += 1
        If $i == $sd_windows[0][0] Then
            If $sd_method == 0 Or $sd_method == 1 Or $sd_method == 2 Then Shutdown(Int($sd_method))
            ExitLoop
        EndIf
    Wend            
EndFunc
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

Even better!

I put it in the first post.

;===============================================================================
;
; Description:      Close all windows according to $sd_method
; Syntax:           _ShutDown($sd_method, $sd_leaveopen)
; Parameter(s):     $sd_method - =====================================================
;                         method 0- close all windows and log off
;                         method 1- close all windows and shutdown
;                         method 2- close all windows and reboot
;                         method 3- close all windows
;                         method 4- close all windows except for $sd_leaveopen
;                         =====================================================
;               $sd_leaveopen - "Window Title|Another|and one more"
;
; Requirement(s):   $sd_method
; Return Value(s):  On Success - None
;                   On Failure - None
; Author(s):        AutoItKing <bendudefu [at] aim [dot] com> and Danny35d
; Note(s):          Use with caution!
;
;===============================================================================
Edited by AutoItKing
http://www.autoitking.co.nr Site is DOWN | My deviantART | No Topic Topic - Don't do it!-------------------- UDF's/Scripts:AutoIt: [BenEditor 3.6] [_ShutDown()]PHP: [CommentScript]Web Based AutoIt: [MemStats] [HTML to AU3] [User LogIn and SignUp script]
Link to comment
Share on other sites

  • 2 months later...
  • 5 months later...

The _shutdown_test.au3 does not work

says line 4

_shutdown(4,"untitled - notpad", "untitled - paint")

_shutdown(4,"untitled - notpad", ^ Error

Wow, I have been away a long time, so long I didn't even see your reply! WOW!

But I fixed it!

_ShutDown_test.au3

http://www.autoitking.co.nr Site is DOWN | My deviantART | No Topic Topic - Don't do it!-------------------- UDF's/Scripts:AutoIt: [BenEditor 3.6] [_ShutDown()]PHP: [CommentScript]Web Based AutoIt: [MemStats] [HTML to AU3] [User LogIn and SignUp script]
Link to comment
Share on other sites

  • 2 months later...

Omg! Where'd you come from? Diggin' up old topics! Jeez!

Lol, I made this a looonng time ago.

http://www.autoitking.co.nr Site is DOWN | My deviantART | No Topic Topic - Don't do it!-------------------- UDF's/Scripts:AutoIt: [BenEditor 3.6] [_ShutDown()]PHP: [CommentScript]Web Based AutoIt: [MemStats] [HTML to AU3] [User LogIn and SignUp script]
Link to comment
Share on other sites

Omg! Where'd you come from? Diggin' up old topics! Jeez!

Lol, I made this a looonng time ago.

found it by luck, so what's the problem? cant reply on old topics?(not so old)

anyway ....

Link to comment
Share on other sites

  • 3 weeks later...

missing flag: #EWX_FORCE

and i think you dont use the required privileges (xp etc.)

from PureBasic: (i used autoit-highlighting, cause its better without any highlighting)

Procedure Shutdown()
  #EWX_LOGOFF = 0
  #EWX_SHUTDOWN = 1
  #EWX_REBOOT = 2
  #EWX_FORCE = 4
  #EWX_POWEROFF = 8
  #TOKEN_ADJUST_PRIVILEGES = 32   
  #TOKEN_QUERY = 8               
  #SE_PRIVILEGE_ENABLED = 2     
  #ANYSIZE_ARRAY = 1
  #VER_PLATFORM_WIN32_NT = 2
  ;#SE_SHUTDOWN_NAME = "SeShutdownPrivilege"
 
  Structure MyLUID
    LowPart.l
    HighPart.l
    Attributes.l
  EndStructure
 
  Structure MyTOKEN
    PrivilegeCount.l
    LowPart.l
    HighPart.l
    Attributes.l
  EndStructure
 
  Global hdlProcessHandle.l
  Global hdlTokenHandle.l
  Global tmpLuid.MyLUID
  Global tkp.MyTOKEN
  Global tkpNewButIgnored.MyTOKEN
  Global lBufferNeeded.l
 
  hdlProcessHandle = GetCurrentProcess_()
 
  OpenProcessToken_(hdlProcessHandle, #TOKEN_ADJUST_PRIVILEGES | #TOKEN_QUERY, @hdlTokenHandle)
 
  ; Get the LUID for shutdown privilege
  SysName.s = "" + Chr(0)
  Name.s = "SeShutdownPrivilege" + Chr(0)
  Erg.l = LookupPrivilegeValue_(SysName, Name, @tmpLuid)
 
  tmpLuid\Attributes = #SE_PRIVILEGE_ENABLED
  tkp\PrivilegeCount = 1
  tkp\LowPart = tmpLuid\LowPart
  tkp\HighPart = tmpLuid\HighPart
  tkp\Attributes = tmpLuid\Attributes
 
  ; Enable the shutdown privilege in the access token of this process
  Erg.l = AdjustTokenPrivileges_(hdlTokenHandle, 0, @tkp, SizeOf(MyTOKEN), @tkpNewButIgnored, @lblBufferNeeded)
  Erg.l = ExitWindowsEx_((#EWX_POWEROFF | #EWX_FORCE), 0)
EndProcedure

hour.l = 01     ; adjust time here
minute.l = 00
second.l = 00

Repeat
  time.l = Date()
  Debug Str(Hour(time)) + " - " + Str(hour)
  Debug Str(Minute(time)) + " - " + Str(minute)
  Debug Str(Second(time)) + " - " + Str(second)
  If Hour(time) = hour And Minute(time) = minute And Second(time) = second
    Shutdown()
    Break
  ;ElseIf Hour(time) = hour And Minute(time) > minute
  ElseIf Hour(time) = hour And Minute(time) = minute And Second(time) > second
    MessageRequester("ShutDownSystemByGivenTime", "Programm vorzeitig beendet")
    Break
  EndIf
  Delay(1000)
ForEver
; IDE Options = PureBasic v3.94 (Windows - x86)
Link to comment
Share on other sites

  • 9 months later...

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...