From 7de62a6295225ece66ab4c666bf837df8e2d3d41 Mon Sep 17 00:00:00 2001 From: Ondra Machacek Date: Mon, 12 Oct 2015 13:37:38 +0200 Subject: [PATCH] modules: adding system module --- winremote/modules/system.py | 75 +++++++++++++++++++++++++++++++++++++ winremote/winremote.py | 1 - 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 winremote/modules/system.py diff --git a/winremote/modules/system.py b/winremote/modules/system.py new file mode 100644 index 0000000..359f488 --- /dev/null +++ b/winremote/modules/system.py @@ -0,0 +1,75 @@ +""" +This module implements work with system +""" + + +def get_process(session, name, attributes='Name,ProcessId'): + """ + Description: return information about process + + :param session: instance of Windows, which hold session to win machine + :type session: winremote.Windows + :param name: name of proccess + :type name: str + :param attributes: comma delimited name of attributes to be returned + :type attributes: str + :returns: info about process, None if process not found + :rtype: dict + """ + return session._wmi.query_first( + "select %s from Win32_process where Name = '%s'" % (attributes, name) + ) + + +def list_processes(session, attributes='Name,ProcessId'): + """ + Description: return list of all proccesses on windows machine + + :param session: instance of Windows, which hold session to win machine + :type session: winremote.Windows + :param attributes: comma delimited name of attributes to be returned + :type attributes: str + :returns: list of processes info + :rtype: list of dict + """ + return session._wmi.query_first( + "select %s from Win32_process" % attributes + ) + + +def arch(session): + """ + Description: return windows architecture + + :param session: instance of Windows, which hold session to win machine + :type session: winremote.Windows + :returns: windows architecture (32-bit, 64-bit, ...) + :rtype: str + """ + return session._wmi.query_first( + "select OSArchitecture from Win32_OperatingSystem" + )['OSArchitecture'] + + +def reboot(session): + """ + Reboot windows machine + + :param session: instance of Windows, which hold session to win machine + :type session: winremote.Windows + :returns: True if cmd successfully ran, False otherwise + :rtype: bool + """ + return session.run_cmd('shutdown /r /t 1')[0] + + +def shutdown(session): + """ + Shutdown windows machine + + :param session: instance of Windows, which hold session to win machine + :type session: winremote.Windows + :returns: True if cmd successfully ran, False otherwise + :rtype: bool + """ + return session.run_cmd('shutdown /s /t 1')[0] diff --git a/winremote/winremote.py b/winremote/winremote.py index 7297c25..991891b 100644 --- a/winremote/winremote.py +++ b/winremote/winremote.py @@ -75,7 +75,6 @@ class WMI(object): """ Class provides access to windows machine via WMI. """ - re_arch = re.compile('^(?P[0-9]+)-bit$', re.IGNORECASE) logger = logging.getLogger('wmi') def __init__(self, session):