[python-win32] manage local drives sharing informations

Tim Golden tim.golden at viacom-outdoor.co.uk
Wed Mar 17 03:28:52 EST 2004


>I would like to manage my sharing informations for all my local drives 
>(eg: name of the share, comments, ...).
>
>
>I've found the following code which can be a start :
>   import wmi
>   system = wmi.WMI ()
>   my_computer = system.Win32_ComputerSystem ()[0]
>   print "Disks on", my_computer.Name
>   for disk in system.Win32_LogicalDisk ():
>      print disk.Caption, disk.Description, disk.ProviderName or ""
>
>but I don't know where to find a list and description of 
>properties such
>as Name, Caption, Description, ProviderName, .......

In essence, you have to go to the appropriate
MSDN page and start from there. (Google for
Microsoft WMI classes). There are other helpful
WMI examples around the net, most of which 
translate quite easily into Python. Just Google
for WMI examples and you'll get loads of useful
hits.

If you take any WMI object (such as my_computer 
or disk in your example above) and print it, you 
usually get a readable output of available fields 
and values. (This is because the Python module calls
the object's GetObjectText_ method).

For example:

<screen dump>

ActivePython 2.2.3 Build 227 (ActiveState Corp.) based on
Python 2.2.3 (#42, Nov 13 2003, 09:57:55) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import wmi
>>> c = wmi.WMI ()
>>> for i in c.Win32_Share (): print i
...

instance of Win32_Share
{
        AllowMaximum = TRUE;
        Caption = "Remote IPC";
        Description = "Remote IPC";
        Name = "IPC$";
        Path = "";
        Status = "OK";
        Type = 2147483651;
};


instance of Win32_Share
{
        AllowMaximum = TRUE;
        Caption = "Remote Admin";
        Description = "Remote Admin";
        Name = "ADMIN$";
        Path = "C:\\WINNT";
        Status = "OK";
        Type = 2147483648;
};


instance of Win32_Share
{
        AllowMaximum = TRUE;
        Caption = "Default share";
        Description = "Default share";
        Name = "C$";
        Path = "C:\\";
        Status = "OK";
        Type = 2147483648;
};

</screen dump>

TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________



More information about the Python-win32 mailing list