Code covered by the BSD License  

Highlights from

Be the first to rate this file! 7 Downloads (last 30 days) File Size: 9.78 KB File ID: #37647



Jan Simon (view profile)


Shutdown, sleep, hibernate etc. of Windows computers

| Watch this File

File Information

WinPower - Mex function to set the power status on Windows computers

Power off, shut down, logoff, sleep, reboot, reboot and restart Matlab, disable/enable sleeping, lock

WinPower(Command, Force)
  Command: String, not case-sensitive.
     'poweroff': Switch power off.
     'reboot': Reboot the machine.
     'logoff': Logoff the current user.
     'shutdown': Shut down the machine to a state, which allows the user to
                  switch off the power securely by hand.
     'sleep': Let the machine fall asleep.
                  The additional arguments 'off' and 'on' disable
                  and enable the sleep mode.
     'hibernate': Write memory to disk and fall into deep sleep.
     'lock': Lock the machine, password is required for wake-up.
     'rebootmatlab': Reboot the machine, restart Matlab when the user is
                  logged in again.
  Force: Kill waiting/crashed applications:
     For 'sleep', 'hibernate' and 'lock' the Force is ignored.
     'noforce': Wait until the applications close voluntarily. Default.
     'force': Close waiting applications. Dangerous.
     'forceifhung': Close waiting and crashed applications. Dangerous.

1. Try a poweroff, do not kill waiting applications:
2. Force a poweroff (unsaved documents are lost!):
     WinPower('poweroff', 'forceifhung');
3. Do not let the computer fall asleep during a long computation:
     WinPower('Sleep', 'off'); Long_Calculation(); WinPower('Sleep', 'on');
4. Reboot the machine and after the user is logged in Matlab is started with
   the bench() function:
     WinPower('RebootMatlab', 'bench(2)');

WinPower runs under Windows only. It can be compiled with MSVC2008/2010, but LCC shipped with Matlab 32bit fails. In case of troubles or for Matlab 6.5 download pre-compiled files:

Tested: Matlab 6.5, 7.7, 7.8, 7.13, WinXP/32, Win7/64
        Compiler: OWC1.8, MSVC2008/2010
Assumed Compatibility: higher Matlab versions, Vista, Windows8.

MATLAB release MATLAB 7.8 (R2009a)
Other requirements MSVC compiler
Tags for This File   Please login to tag files.
Please login to add a comment or rating.

Contact us