list drives

This commit is contained in:
Alessandro ZANNI 2016-10-03 16:44:41 +02:00
parent 5d717cefe6
commit 1b5a1af7aa
1 changed files with 14 additions and 18 deletions

View File

@ -1,6 +1,7 @@
# -*- coding: UTF8 -*- # -*- coding: UTF8 -*-
from pupylib.PupyModule import * from pupylib.PupyModule import *
import ctypes # import ctypes
from pupylib.utils.rpyc_utils import redirected_stdio
__class_name__="Drives" __class_name__="Drives"
@ -8,19 +9,14 @@ __class_name__="Drives"
class Drives(PupyModule): class Drives(PupyModule):
""" List valid drives in the system """ """ List valid drives in the system """
dependencies=["win32api","win32com","pythoncom","winerror"]
def init_argparse(self): def init_argparse(self):
self.arg_parser = PupyArgumentParser(prog="drives", description=self.__doc__) self.arg_parser = PupyArgumentParser(prog="drives", description=self.__doc__)
def run(self, args): def run(self, args):
blen = self.client.conn.modules['ctypes'].c_uint(128) self.client.load_package("wmi")
rv = self.client.conn.modules['ctypes'].c_uint() self.client.load_package("pupwinutils.drives")
bufs = self.client.conn.modules['ctypes'].create_string_buffer(128)
rv = self.client.conn.modules['ctypes'].windll.kernel32.GetLogicalDriveStringsA(blen, bufs) with redirected_stdio(self.client.conn):
if rv == 0: self.client.conn.modules['pupwinutils.drives'].list_drives()
self.log('Error retrieving logical drives')
drives = bufs.raw.split('\0')
for drive in drives:
if drive:
self.log('- %s' % drive)
else:
break