Jump to content
Sign in to follow this  
Lemmens Peter

Shutdown does not seems to work

Recommended Posts

Lemmens Peter

Hi,

I wanted to create a script that shuts-down a computer everyday at 19:00. (End of workday)

So I created a script and added it in the "scheduled tasks" to run.

My script works correctly when the user is logged in (even when the computer is locked by a user)

But my script DOES NOT work when nobody is logged in.

To check what the script did, I add a comment-line to a log-file each time the script is executed.

My script always says the shutdown was a success even when it did NOT shut-down (when nobody is logged on)

Can it be a bug of am I missing something ?

Best regards and thank you,

Peter

$Data_Title = StringLeft(@ScriptName, StringInStr(@ScriptName, "." ,0,-1)-1)
$Log_File = @ScriptDir & "\" & $Data_Title & ".csv"

    Sleep(1000)
    If Shutdown(1 + 4 + 8 +16) = 1 Then
        ; 0 = Logoff; 1 = Shutdown; 2 = Reboot; 4 = Force; 8 = Power down; 16= Force if hung; 32= Standby; 64= Hibernate
        FileWriteLog($Log_File, @YEAR & "/" & @MON & "/" & @MDAY & ";" & @HOUR & ":" & @MIN & ";Shutdown;Success")
        ; If Shutdown is a success a line will be added to the log_File. Exemple of such a line :
        ; 2009/01/11;21:53;Shutdown;Success
    Else
        FileWriteLog($Log_File, @YEAR & "/" & @MON & "/" & @MDAY & ";" & @HOUR & ":" & @MIN & ";Shutdown;Failure")
        ; If Shutdown is NOT a success a line will be added to the log_File. Exemple of such a line :
        ; 2009/01/11;21:53;Shutdown;Failure
    EndIf
    Sleep(1000)
    Exit

Func FileWriteLog($sLogPath, $sLogMsg)
    Local $hOpenFile
    Local $hWriteFile
    $hOpenFile = FileOpen($sLogPath, 1)
    If $hOpenFile = -1 Then
        SetError(1)
        Return 0
    EndIf
    $hWriteFile = FileWriteLine($hOpenFile, $sLogMsg)
    If $hWriteFile = -1 Then
        SetError(2)
        Return 0
    EndIf
    FileClose($hOpenFile)
    Return 1
EndFunc
Edited by Lemmens Peter

Share this post


Link to post
Share on other sites
fctd

When you force a shutdown, is the script fast enough to write something succesfully to a file? :)

Little script without using the "scheduled tasks".

shutdown

Greetings.


[list][font="Century Gothic"]If nothing is certain, everything is possible.[/font][/list][font="Century Gothic"]Experience is something you get, just after you need it.[/font]

Share this post


Link to post
Share on other sites
Lemmens Peter

Yes, the script is fast enough to write to a log-file.

Is there anyone wo knows why it does not shutdown when nobody is logged-on ?

Am I doing something wrong ?

Thanks and best regards,

Peter

Share this post


Link to post
Share on other sites
fctd

Maybe try this Shutdown(5)

Gr.


[list][font="Century Gothic"]If nothing is certain, everything is possible.[/font][/list][font="Century Gothic"]Experience is something you get, just after you need it.[/font]

Share this post


Link to post
Share on other sites
C45Y

Is there anyone wo knows why it does not shutdown when nobody is logged-on ?

someone correct me if im wrong but scheduled tasks need a logged on account to run...

dirty fix would be if your on xp box you could replace the uilman.exe in sys32 i think. it's the only proecess that i know of that can be run when not logged on...but then you'd still have to start it by [win] + ...

i give up...hope you find a solution


http://twentylinesofcode.blogspot.comLittle apps n crap. can be fun

Share this post


Link to post
Share on other sites
fctd

someone correct me if im wrong but scheduled tasks need a logged on account to run...

But why does it write to the log file with ";Shutdown;Success". It must be running then.

Greetings.


[list][font="Century Gothic"]If nothing is certain, everything is possible.[/font][/list][font="Century Gothic"]Experience is something you get, just after you need it.[/font]

Share this post


Link to post
Share on other sites
Manjish

But why does it write to the log file with ";Shutdown;Success". It must be running then.

Greetings.

Hey why don't u make a batfile for the shutdown script, and then run that batfile using schtasks. n I am definatedly sure, that if the computer is locked, or the user is logged off, the schtasks do work. I have tried this myself. While scheduling the task, make sure u unselect the "Run only if logged" on option, and enter the username and password of the m/c while scheduling the task.

bat file will contain:

shutdown -s -t 20 >c:\test.log

This will write the result into logfile too.


[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites
Manjish

Also u can use the schtasks option from cmd prompt as:

schtasks /ru username /rp "password" /sc daily /st 00:19:00 /tr c:\shutdown.bat /tn "shutdown"


[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites
Manjish

hey i just was reading the help file for shutdown function..

there is no "16" in it.

The shutdown code is a combination of the following values:

0 = Logoff

1 = Shutdown

2 = Reboot

4 = Force

8 = Power down

32= Standby

64= Hibernate


[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites
fctd

There is a '16'

0 = Logoff

1 = Shutdown

2 = Reboot

4 = Force

8 = Power down

16= Force if hung

32= Standby

64= Hibernate


[list][font="Century Gothic"]If nothing is certain, everything is possible.[/font][/list][font="Century Gothic"]Experience is something you get, just after you need it.[/font]

Share this post


Link to post
Share on other sites
IKilledBambi

for the .bat if I put shutdown -s in a bat file it executes the script at lightning speed and never lets it happen, I think this may be a firewall or something.

Share this post


Link to post
Share on other sites
Manjish

There is a '16'

0 = Logoff

1 = Shutdown

2 = Reboot

4 = Force

8 = Power down

16= Force if hung

32= Standby

64= Hibernate

Hey i am using the latest version v3.2.12.1 of autoit.. my help file doesn't have a 16


[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites
Manjish

for the .bat if I put shutdown -s in a bat file it executes the script at lightning speed and never lets it happen, I think this may be a firewall or something.

hey it doesn't execute at lightening speed, the -t 20 specifies 20 sec timeout to shutdown. u can specify any time to delay it.


[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites
Lemmens Peter

Hi AutoIt-lovers,

First of all:

I'm also using the latest official version 3.3.0.0 and the help states there is a "16"

0 = Logoff

1 = Shutdown

2 = Reboot

4 = Force

8 = Power down

16= Force if hung

32= Standby

64= Hibernate

Secondly :

The script runs (with sheduled tasks using a user and password, etc) even when no user is logged on.

The command "shutdown" return a 1 (Success).

A line is added in the log-file saying "success" but the computer does NOT restart.

So I think it's a bug.

How can I report this as a bug ?

I hope this helps to improve AutoIt

because AutoIt IS a great scripting-tool :)

Best regards,

Peter

Share this post


Link to post
Share on other sites
Ward Gerlach

When you're creating the Scheduled Task, if you specify "System" as the user account, it will use the "NT AUTHORITY/SYSTEM" account to perform the task - even if no one is logged into the machine at the scheduled time, and no password is required.

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  

×