Sign in to follow this  
Followers 0
BOUNCER

execute script on shutdown

8 posts in this topic

i want to have the script execute on machine shutdown, so as soon as shutdown is intiiated i want the script to start working, how can this be done , thanks

Share this post


Link to post
Share on other sites



maybie you can do this if you find out which process closes itself first when you click "shutdown", I set you en example with explorer.exe (this is just a hint, I took a wild guess):

AdlibEnable("Adlibfunc", 10)
func adlibfunc ()
    if Not ProcessExists("explorer.exe") Then call("func1")
EndFunc

func func1()
    AdlibDisable()
    ;your script code
EndFunc

but maybie you can use "smss.exe" or "csrss.exe" or "svchost.exe" or any other of the system's processes that are allways launched during windows work time, which closes themselves down together with "shutdown" button.

but I say you again, this is just a guess. :)

Share this post


Link to post
Share on other sites

If you are using Windows XP or 2000, use the built in shutdown script option. Launch gpedit.msc then go to Computer Configuration | Windows Settings | Scripts (Startup/Shutdown). Double click on Shutdown, select Add then browse to your script. Click OK and you're done.


Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

Share this post


Link to post
Share on other sites

i already tried that, i have this server that runs in dos mode, and the computer has no monitor only way i can control it is through remote admin, so once internet disconnects i have to shut it down, but it never shuts down cause the dos server program is open, until it is closed the machine will not shut down or restart or anything, i tried running kill scripts from the Scripts (Startup/Shutdown) but it seems to hang that and never gets around to doing it, the only way to close is it either kill the process or ctrl + c

Share this post


Link to post
Share on other sites

My real low tech solution is to run this script at system startup

opt("TrayIconHide",1)

While 1

Sleep(60000)

WEnd

Func onAutoItExit()

; Add things to do when the system shuts down here, but be fairly quick

;

EndFunc

I said it was low tech!

Share this post


Link to post
Share on other sites

i already tried that, i have this server that runs in dos mode, and the computer has no monitor only way i can control it is through remote admin, so once internet disconnects i have to shut it down, but it never shuts down cause the dos server program is open, until it is closed the machine will not shut down or restart or anything, i tried running kill scripts from the Scripts (Startup/Shutdown) but it seems to hang that and never gets around to doing it, the only way to close is it either kill the process or ctrl + c

Correct me if i'm wrong but when you shutdown your computer windows can be told to not wait for processes to be closed correctly. So if the program doesn't respond for like 4-8 seconds it is killed. Will that solve your problem?

Modify these ?

[HKEY_CURRENT_USER\Control Panel\Desktop]

"AutoEndTasks"="1"

"HungAppTimeout"="100"

"WaitToKillAppTimeout"="1000"

Here's the whole file for startup/shutdown speedup.

Windows Registry Editor Version 5.00

;===================================================================================================

; **************************************** Startup / Shutdown ****************************************

;===================================================================================================

;Determines whether the Welcome to Windows splash screen, Welcome.exe,appears the next time the user logs on.

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\tips]

"Show"=dword:00000000

;--------------------------------------------------------------------------------------------------------------------------------

; Allows boot files to be placed optimally on the hard-drive for faster boots.

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Dfrg\BootOptimizeFunction]

"Enable"="Y"

;--------------------------------------------------------------------------------------------------------------------------------

; Speed up shutdown

[HKEY_CURRENT_USER\Control Panel\Desktop]

"AutoEndTasks"="1"

"HungAppTimeout"="100"

"WaitToKillAppTimeout"="1000"

;--------------------------------------------------------------------------------------------------------------------------------

; Disable Automatic Restart in the event of a BSOD

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CrashControl]

"AutoReboot"=dword:00000000

;--------------------------------------------------------------------------------------------------------------------------------

; Prefetcher tweak (faster booting) boot and program prefetch use 00000003 or Boot only 00000002

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\PrefetchParameters]

"EnablePrefetcher"=dword:00000003

;--------------------------------------------------------------------------------------------------------------------------------

; Modifying the Autocheck Time-out Value NTFS ONLY When Windows is not shutdown correctly it will perform an AutoCheck using CHKDSK on the next restart. This setting controls the time delay before running Autochk or whether it is run at all.

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager]

"AutoChkTimeOut"=dword:00000002

;--------------------------------------------------------------------------------------------------------------------------------

; Clear the Page File at System Shutdown for security (makes shutdown slower when activated)

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management]

"ClearPageFileAtShutdown"=dword:00000001

;--------------------------------------------------------------------------------------------------------------------------------

; Disable Hibernate

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Power]

"Heuristics"=hex:05,00,00,00,00,01,00,00,00,00,00,00,00,00,00,00,3f,42,0f,00

;--------------------------------------------------------------------------------------------------------------------------------

; Disable Shutdown Event Tracker

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows NT\Reliability]

"ShutdownReasonOn"=dword:00000000

"ShutdownReasonUI"=dword:00000000


My little company: Evotec (PL version: Evotec)

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