Sign in to follow this  
Followers 0
CraigC

Shutdown script

9 posts in this topic

Hi

I am writing a script to save all documents and power down a pc. I thought I would leave the shutdown till last, because in theory this is the easiest and work on saving the documents behins a locked screen first.

Although I have completed the saving of the documents section the shutdown is not working either using the autoit command or as a batch file which executes either the XP command or NT Resource Kit shutdown.

To elaborate further I have put the shutdown command to execute at a certain time within autoit and then to run the shutdown command. When the screen is unlocked the command (either autoit's or the batch file) shuts down the pc. However when the screen is locked the autoit command does nothing and the batch just winges about permissions or i have used the wrong command line in the batch file. This happens on either windows xp or windows 2000. The logged on user has local admin permissions and there is no domain policy in place to prevent shutdown.

I have searched the autoit help/forums and google to see if there is something special that happens when a locked screen is active within windows with no success. Also this does not explain even if a screen is locked why i can still remotely shutdown the pc.

I cannot run the program through the task scheduler as it needs to run as the active user to allow the documents to be saved. Testing has proven that I need to do this. Also I cannot run the Autoit program as a service because of the same issue it needs to run as the logged on user..

my small autoit shutdown code is

CODE
#include <Date.au3>

While 1

If _NowTime(4) = "20:00" Then

ExitLoop

EndIf

Sleep(1)

WEnd

RunWait("C:\Program Files\PC Shutdown\shutdown.bat")

;Shutdown(9) - i alternate between this and the previous command for testing

my batch file which works if the screen is not locked is as follows:

CODE
"C:\Program Files\PC Shutdown\shutdown.exe" /l /y /t:0 /l

Any assistance would be appreciated in this last and what should be easy hurdle.

Thanks

Craig

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Ok? Why use a .bat?

While 1
  Sleep(10)
  if _nowtime(4) = "20:00" then Shutdown(9)
Wend

If the scheduler is configured to run the program as the user with his/her log/pass, it doesn't care if the screen is locked.

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

Ok? Why use a .bat?

While 1
  Sleep(10)
  if _nowtime(4) = "20:00" then Shutdown(9)
Wend

If the scheduler is configured to run the program as the user with his/her log/pass, it doesn't care if the screen is locked.

because i will be deploying the full shutdown/save program to about 800 workstations i would need to capture all of their username/passwords to run the scheduled task as the user. I think you will agree this is quite impractical. this is why is stopped using the internal shutdown command and tried to look at a batch file which i have previously used on my servers.

the other reason why the shutdown is outside the loop is because when the time reaches 20:00 it repeatedly executes the shutdown batch file until the time changes to 20:01. if i change the time to 20:00:00 then the shutdown batch file doesnt have time to execute as soon as it changes to 20:00:01.

Share this post


Link to post
Share on other sites

because i will be deploying the full shutdown/save program to about 800 workstations...

Well that is one of the most beautiful examples of 'never do such a thing' if you are an admin (not meant as offense).

If you have a site policy whereafter all workstations are to be off at 8 PM and your users know it, they are advised to take care about saving their work before leaving desk. However trying blindly to do something like Ctrl+S in all open programs from a service or such is a horrible security hole!!!

As for you problem with locked workstations: why not install your script as a screensaver (like WinExit from MS)? Of course only to shutdown not to 'save documents'.


UDFS & Apps:


DDEML.au3 - DDE Client + Server[*]
Localization.au3- localize your scripts[*]
TLI.au3 - type information on COM objects (TLBINF emulation)[*]
TLBAutoEnum.au3 - auto-import of COM constants (enums)[*]
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector

- OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

Share this post


Link to post
Share on other sites

i resolved my issue. i have read on another forum that when you have a locked screen and you need to issue a shutdown command you need to use the flag to force processes to close/force shutdown. In autoit this has meant using

Shutdown(13) instead of shutdown(9) which worked fine.

whilst it is not a clean shutdown my relevant processes will closed and documents saved with the first part of the code before the shutdown is invoked.

thanks,

craig

Share this post


Link to post
Share on other sites

Well that is one of the most beautiful examples of 'never do such a thing' if you are an admin (not meant as offense).

If you have a site policy whereafter all workstations are to be off at 8 PM and your users know it, they are advised to take care about saving their work before leaving desk. However trying blindly to do something like Ctrl+S in all open programs from a service or such is a horrible security hole!!!

As for you problem with locked workstations: why not install your script as a screensaver (like WinExit from MS)? Of course only to shutdown not to 'save documents'.

i totally agree with your comment about it being a security hole and have advised that it really should be actioned as a company policy in our HR/computer policy document to enforce it.

however i have successfully been able to save power point, word, excel, access and close outlook behind a locked screen and now i can do the final shutdown.

Share this post


Link to post
Share on other sites

I didn't mean to sound snippish, and I understand your point. Our company has a similar policy, but doesn't care if anything's open. The network server initiates a shutdown command at $time (usually about 0200), and the workstations reboot.


Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

no offence taken. i have a feeling we will end up doing something similar and getting a server to do the shutdown remotely and monitor who is complying.

i trialled a package last year that used ms sms to do the deployment, saving and shutdown but this is expensive.

we heard about autoit in a coumputer journal and i was asked to investigate as i have mixture of skills unix/windows/networking etc...

i am glad i found the language but wish i had known about it several years ago when i was using kix to manage my smaller network.

it is very flexible and this recent project has made an advocate to automate anything which requires some manual work.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

You could always build a client/server program with the TCP/IP functions in AutoIt, have each machine listening on port $x for command from server, and then do Shutdown(13) when it receives a specific packet.

I mean ... if you're that bored....

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

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