PC commands

From Enso Wiki

Jump to: navigation, search
  • NOTE: This command is created for Command Server not as a standalone command
  • NOTE: This plugin requires pywin32

[edit] Code

from base import BaseCommand
import ctypes
import win32api 
 
class Command(BaseCommand):
    def __init__(self, *args):
        BaseCommand.__init__(self, *args)
 
        self.newCommand("lock pc",
                                self._lockPC,
                                "Locks the PC.",
                                "<p>The lock pc command locks the computer.</p>"
        )
        self.newCommand("shutdown pc",
                                self._shutPC,
                                "Shut down the PC.",
                                "<p>The shutdown pc command shuts down the computer.</p>"
        )
        self.newCommand("reboot pc",
                                self._rebootPC,
                                "Reboot the PC.",
                                "<p>The reboot pc command reboots the computer.</p>"
        )
 
        self.newCommand("logoff pc",
                                self._logoffPC,
                                "Log off the PC.",
                                "<p>The logoff pc command logs of the computer.</p>"
        )
 
    #Command Methods
    def _lockPC(self, postfix):
        ctypes.windll.user32.LockWorkStation ()
 
    def _shutPC(self, postfix):
        try:
            win32api.ShellExecute(0, 'open', 'c:\windows\system32\shutdown.exe' , '-s', None, 1)
        except:
            self.displayMessage('Error shutting down')
 
    def _rebootPC(self, postfix):
        try:
            win32api.ShellExecute(0, 'open', 'c:\windows\system32\shutdown.exe' , '-r', None, 1)
        except:
            self.displayMessage('Error rebooting')
 
    def _logoffPC(self, postfix):
        try:
            win32api.ShellExecute(0, 'open', 'c:\windows\system32\shutdown.exe' , '-l', None, 1)
        except:
            self.displayMessage('Error logging off')