Working with Share Information
Windows NT defines the concept of a share . A share is a resource published by a machine designed for sharing with multiple users. Shares are usually disk-based shares or printers.
To obtain information about a share or to enumerate the shares
available on a Windows NT server, the
win32net.NetShare*()
family of functions are
used, with PySHARE_INFO_* as the corresponding
data structures. The process for shares is identical to the process
for working with users and servers, as we described previously.
For example, you can use the
win32net.NetShareEnum()
function to view the shares published
by a server. This function is almost identical to the other
enumerator functions described in this chapter, so you can use the
following code to read the first few shares at your local machine at
information level 0:
>>> data, total, resume = win32net.NetShareEnum(None, 0) >>> for share in data: ... print share['netname'] ... ... ADMIN$ IPC$ cdrom C$ c_drive l_drive L$ >>>
Note that you haven’t looped calling the function, so you get only the first few shares that may be available.
A new share can be created on a server using
win32net.NetShareAdd(). This function requires
data in information level 2, a PyNET_SHARE_INFO_2
structure. By referring to Appendix B, you can find
the data necessary to create a share. The following code shows how to
create a share to the local C:\TEMP directory:
>>> data={} >>> data['netname']="TEMPSHARE" >>> data['type']=win32netcon.STYPE_DISKTREE ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access