Skip to content

Commit

Permalink
modules: adding system module
Browse files Browse the repository at this point in the history
  • Loading branch information
machacekondra committed Oct 12, 2015
1 parent fe868a1 commit 7de62a6
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
75 changes: 75 additions & 0 deletions winremote/modules/system.py
Original file line number Diff line number Diff line change
@@ -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]
1 change: 0 additions & 1 deletion winremote/winremote.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class WMI(object):
"""
Class provides access to windows machine via WMI.
"""
re_arch = re.compile('^(?P<type>[0-9]+)-bit$', re.IGNORECASE)
logger = logging.getLogger('wmi')

def __init__(self, session):
Expand Down

0 comments on commit 7de62a6

Please sign in to comment.