Example #1
0
def CreateUserAndShare(userName, fullName):
    homeDir = "%s\\%s" % (serverName, userName)
    # Create user data in information level 3 (PyUSER_INFO_3) format.
    userData = {}
    userData['name'] = userName
    userData['full_name'] = fullName
    userData['password'] = userName
    userData['flags'] = win32netcon.UF_NORMAL_ACCOUNT | win32netcon.UF_SCRIPT
    userData['priv'] = win32netcon.USER_PRIV_USER
    userData['home_dir'] = homeDir
    userData['home_dir_drive'] = "P:"
    userData['primary_group_id'] = ntsecuritycon.DOMAIN_GROUP_RID_USERS
    userData['password_expired'] = 1 # User must change password next logon.

    # Create the user
    win32net.NetUserAdd(serverName, 3, userData)

    # Create the new directory, then the share
    dirName = os.path.join(homeRoot, userName)
    os.mkdir(dirName)
    shareData = {}
    shareData['netname'] = userName
    shareData['type'] = win32netcon.STYPE_DISKTREE
    shareData['path'] = dirName
    shareData['max_uses'] = -1
    # The security setting for the share.
    sd = CreateUserSecurityDescriptor(userName)
    shareData['security_descriptor'] = sd
    # And finally create it.
    win32net.NetShareAdd(serverName, 502, shareData)
def share():
    shinfo = {}
    folder = "c:\\test"
    shinfo['netname'] = os.path.basename(folder)
    shinfo['type'] = win32net.STYPE_DISKTREE
    shinfo['remark'] = 'data files'
    shinfo['premissions'] = 0
    shinfo['max_users'] = -1
    shinfo['current_users'] = 0
    shinfo['path'] = 'c:\\test'
    shinfo['passwd'] = ''
    server = r'\\'
    win32net.NetShareAdd(server, 2, shinfo)
Example #3
0
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)
if not os.path.isdir(pathname):
    os.mkdir(pathname)

# Share directory over Public Network.
drive, sharename = os.path.split(pathname)
shinfo = {}
shinfo['netname'] = sharename
shinfo['type'] = win32netcon.STYPE_DISKTREE
shinfo['remark'] = 'data files'
shinfo['permissions'] = 0
shinfo['max_uses'] = -1
shinfo['current_uses'] = 0
shinfo['path'] = pathname
shinfo['passwd'] = ''
if not os.path.isdir('//' + client_hostname + '/' + sharename):
    win32net.NetShareAdd(client_hostname, 2, shinfo)

serverip_textfile = '//' + client_hostname + '/' + sharename + '/' + 'server_id.txt'

if not os.path.isfile(serverip_textfile):
    open(serverip_textfile, 'w+')

if os.stat(serverip_textfile).st_size == 0:

    def send_data():
        f = open(serverip_textfile, 'w+')
        f.write(boss_ip_Entry.get())
        window.destroy()

    window = tkinter.Tk()
    window.title('Server IPv4 Address')