Page 1 of 1

StartUp, LogOn, LogOff, and ShutDown Scripts

Posted: 2011 Oct 11, 19:56
by Thracx
Windows (and other OSes) lets you run scripts when it starts or stops, or when a user logs on or off.  I use the StartUp & LogOn events to configure my RamDisk, but that's mainly for historical reasons (the RamDisk software I used to use didn't have a Windows Service option).

Does anybody use this feature, and if so, for what?

Posted: 2011 Oct 11, 21:24
by Kilmatead
Tangentially, I remember once being frustrated by wanting to run certain things only upon Wakeup from Sleep (as opposed to Startup or Logon), and after lots of experimentation came up with this:

Code: Select all

Option Explicit

Dim wmiPowerManagementEvent, oShell
Const cntEventEnteringWakeup = 7

Set wmiPowerManagementEvent = GetObject("winmgmts:").ExecNotificationQuery("Select * from Win32_PowerManagementEvent")
Do
   If wmiPowerManagementEvent.NextEvent.EventType = cntEventEnteringWakeup Then
      set oShell=createobject("WScript.Shell")
      oShell.Run """" + "{Insert Programme to Run on Wakeup Here}" + """"
   End If
Loop
Effectively used as a means of (for example) forcing (permanently running) email-clients to check for mail immediately upon wakeup, rather than waiting for their normal timeout cycle to reoccur... which could be any number of minutes, depending on when the computer was put to sleep (humanely) in the first place.

I'm not sure if the task scheduler allows for this now in an easier form or not (it never used to)... but I had more fun figuring out how to do it manually rather than actually having a practical purpose for it at the time.  (I'm easily amused. :wink:)

Posted: 2011 Oct 11, 21:41
by Thracx
Kilmatead wrote:...upon Wakeup from Sleep...
Nice, might come in handy sometime with my HTPC - thanks!
Kilmatead wrote:...but I had more fun figuring out how to do it manually rather than actually having a practical purpose for it at the time.  (I'm easily amused. :wink:)
And behold - you've discovered the Meaning of Life!!!   8)

(Seriously - enjoying while learning, one of the best uses of time!)