Jump to content

+shutdown +lock


Recommended Posts

OK after going through 10+ pages I give up.

I downloaded a script a while back that would shutdown the pc - shutdown(x)

I have a few issues - I want to make sure that if the screensaver is going, applications are running, and/or the computer is locked - that the @$@#$@#$ PC turns off and reboots - or just turns off.

Without pushing the button to turn it off since no one does that anyway.

I run a process that does a test on the server databse everynight - if a user is logged on to the application the test fails. I need to make sure no one is logged on and make sure the computer has been rebooted.

So I added this shutdown(x) to a EXE and copied it to every computer that logs onto my network. I then added a scheduled task to shutdown/restart at a certain time every day. This part works - the file is copied and the task is scheduled - what does not happen is the shutdown.

#include-once

; ------------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language:       English
; Description:    Functions that assist with closing windows.
;
; ------------------------------------------------------------------------------


;===============================================================================
;
; Description:      Close all windows according to $sd_method
; Syntax:           _ShutDown($sd_method, $sd_leaveopen, $sd_leaveopen2, $sd_leaveopen3)
; Parameter(s):     $sd_method - =====================================================
;                                method 1- close all windows and log off
;                                method 2- close all windows and shutdown
;                                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", $sd_leaveopen2="Program Manager", $sd_leaveopen3="Program Manager")
    
    $i=1
    If $sd_method = 1 Then
        $sd_windows = WinList()
        While 1
            If $sd_windows[$i][0] <> "" AND BitAnd( WinGetState($sd_windows[$i][1]), 2 ) AND $sd_windows[$i][0] <> "Program Manager" Then
                WinClose($sd_windows[$i][0])
            EndIf
            $i = $i + 1
            If $i = $sd_windows[0][0] Then
                    Shutdown(0)
                    ExitLoop
            EndIf
        Wend        
    EndIf
    
    $i=1
    If $sd_method = 2 Then
        $sd_windows = WinList()
        While 1
            If $sd_windows[$i][0] <> "" AND BitAnd( WinGetState($sd_windows[$i][1]), 2 ) AND $sd_windows[$i][0] <> "Program Manager" Then
                WinClose($sd_windows[$i][0])
            EndIf
            $i = $i + 1
            If $i = $sd_windows[0][0] Then
                    Shutdown(1)
                    ExitLoop
            EndIf
        Wend        
    EndIf
    
    $i=1
    If $sd_method = 3 Then
        $sd_windows = WinList()
        While 1
            If $sd_windows[$i][0] <> "" AND BitAnd( WinGetState($sd_windows[$i][1]), 2 ) AND $sd_windows[$i][0] <> "Program Manager" Then
                WinClose($sd_windows[$i][0])
            EndIf
            $i = $i + 1
            If $i = $sd_windows[0][0] Then
                    ExitLoop
            EndIf
        Wend        
    EndIf
    
    $i=1
    If $sd_method = 4 Then
        $sd_windows = WinList()
        While 1
            If $sd_windows[$i][0] <> "" AND BitAnd( WinGetState($sd_windows[$i][1]), 2 ) AND $sd_windows[$i][0] <> "Program Manager"  AND $sd_windows[$i][0] <> $sd_leaveopen AND $sd_windows[$i][0] <> $sd_leaveopen2 AND $sd_windows[$i][0] <> $sd_leaveopen3 Then
                WinClose($sd_windows[$i][0])
            EndIf
            $i = $i + 1
            If $i = $sd_windows[0][0] Then
                    ExitLoop
            EndIf
        Wend        
    EndIf
EndFunc

I think the above code is what I am using in this exe - but I am not sure as I have tried so many. I guess it could just shutdown(6) - by the way - can someone PM me about how to reverse the EXE to a AU3 for future issues.

EDIT - had a hard time uploading EXE file - why are others aloud to upload them - but I am not?

I even renamed it - here is the ZIP

EDIT removed all the extra ZIP files - anyone know why I am unable to upload the EXE?

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

HI,

haven't looked at your code, but did you try the func shutdown? There is an exe you could use which decompiles your exe. Decomplie exe to Script in the Autoit folder.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Thanks for your help - I was able to pull the exe into au3 and the only command was

Shutdown(6)

so how do I force a force on the shutdown command?

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

so how do I force a force on the shutdown command?

So I added this shutdown(x) to a EXE and copied it to every computer that logs onto my network. I then added a scheduled task to shutdown/restart at a certain time every day. This part works - the file is copied and the task is scheduled - what does not happen is the shutdown.

well, regular user might not have permission to shutdown the computer (can be set via GPO). What user account did you use for the scheduled task?

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

well, regular user might not have permission to shutdown the computer (can be set via GPO). What user account did you use for the scheduled task?

Cheers

Kurt

For my test I am using myself - I have complete admin rights on the workstation - not on the server. I am able to run the command by itself, so I am assuming that it is getting stuck with work station locked or a program holding it up.

I have again tested this - with outlook opened, the data application in question opened, and a keylocks script from autoit forum that allows me to see NUM, CAPS, SCROLL - on or off status. I am going to test again by locking the computer with no application running - as in this last test the computer was not even locked - and it did not work. I will be back after a reboot - :whistle: if it happens.

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

You could enter "shutdown -t 0 -f" at the command prompt which will perform a forced shutdown immediately.

If I could get them (users) to do that everynight - I could ask them to shutdown their PC - which does not happen. I would like to do this on a time per day - like 12:30 am or something.

Anyway after my test - shutdown(6) - turned into EXE file

with nothing running - did not run

with nothing running and putting username and password into the scheduled task - it rebooted and worked

with keylocks (autoit exe file) running and username and password in the scheduled task - did not run

any ideas - as I did not go any further cause of the autoit script that is running did not work???

edit spelling

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

Holde off - doing another test - as I had the wrong date for the script running for keylocks

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

OK - now it seems to work, I guess what I am missing is that this was not an autoIT issue at all, but the schedule task needs username and password.

This should be moved to chat forum...

I need to know how to add the user name and password into the AT command that I am pushing from the server. I will look it up, but would like some help if you know it.

Thanks

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

If I could get them (users) to do that everynight - I could ask them to shutdown their PC - which does not happen. I would like to do this on a time per day - like 12:30 am or something.

I didnt mean for the user to enter this command. Id do it like this:

#include <Process.au3>

_RunDOS( "shutdown -t 0 -f" )

and you can use the @HOUR and @MIN to perform this at a certain time everyday.

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Link to comment
Share on other sites

I didnt mean for the user to enter this command. Id do it like this:

#include <Process.au3>

_RunDOS( "shutdown -t 0 -f" )

and you can use the @HOUR and @MIN to perform this at a certain time everyday.

I think I would have the same problem - running it as a schedule task, otherwise it would have to run through out the day to check the time every x seconds.

Is there a way to set the schduled task to run with user credentials as then I could just push the task to the end user?

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

at /?
:whistle:
no username or password flag - i did find another command schtasks but I have never used it and will have to do some testing - also have to find out if it is only on XP or is also under Win2K

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

I think this can help you.

Thanks for your help: This should work...

The XP schtasks.exe command-line tool is great for managing scheduled tasks. Win2K doesn't have an equivalent command-line tool. If you attempt to run schtasks.exe on a Win2K machine, you'll receive an error message indicating that you're using the incorrect OS version. You can modify schtasks.exe to work under Win2K by performing the following steps.

Open schtasks.exe in a hexadecimal editor such as BreakPoint Software's Hex Workshop 3.1.

Find code location CB2A, and change the hex value 75 to EB. If you're using Windows XP Service Pack 1 (SP1), the code location is 0x0000CC50 (not CB2A); if you're using XP SP2, the location is 0x0000E3F8.

Save the file and exit the editor.

For cosmetic purposes, you can use Visual C++ or a resource editor such as Angus Johnson's Resource Hacker to change the error message

ERROR: The Target system must be running Windows XP or above.

to

ERROR: The Target system must be running Windows 2000 or above.

This error message is located in String Table 344.

Thanks to John Eccles for this information.

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

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