Welcome, guest | Sign In | My Account | Store | Cart

The following code is an example of how one would use python's win32net module to create a share on windows.

Python, 16 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
import win32net
import win32netcon

shinfo={}

shinfo['netname']='python test'
shinfo['type']=win32netcon.STYPE_DISKTREE
shinfo['remark']='data files'
shinfo['permissions']=0
shinfo['max_uses']=-1
shinfo['current_uses']=0
shinfo['path']='c:\\my_data'
shinfo['passwd']=''
server='servername'

win32net.NetShareAdd(server,2,shinfo)

The python win32 documentation is rather terse about what you need to create a share with win32net. It comments that you need a dictionary holding the share data, in the format of SHARE_INFO_*. You'd need to consult the win32 SDK (try http://msdn.microsoft.com) to find out what that really means. After doing so, you end up with a data structure like the python dictionary above. And, the constants you need for the data structure are located in the win32netcon module.