スクリーンセーバの On/Off

こんなのでいいのではないかな。要 Python Win32 拡張。

import win32gui
from win32con import *

if 'WScript' in globals():
    echo = WScript.Echo
else:
    import sys
    def echo(s):
        win32gui.MessageBox(0, s, sys.argv[0], MB_OK)

msgs = {True: 'on', False: 'off'}

current_state = win32gui.SystemParametersInfo(SPI_GETSCREENSAVEACTIVE)
current_state = not current_state
win32gui.SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, current_state)
echo('screensaver %s' % msgs[current_state])

で、あとは .pys として保存して WSH として実行しても良いし、

from distutils.core import setup
import py2exe

py2exe_options = {
    'compressed': 0,
    'optimize': 2,
    'bundle_files': 3,
}

setup(
    options = {'py2exe': py2exe_options},
    windows = ['toggle_screensaver.pys'],
)
% python setup.py py2exe

てな感じで、py2exe でバイナリを生成しても良い。