473,544 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to create a new user in windows platform using python?

6 New Member
please give me a hand, anything about this topic is welcome.
thanks
Jul 24 '07 #1
6 15943
bartonc
6,596 Recognized Expert Expert
please give me a hand, anything about this topic is welcome.
thanks
Expand|Select|Wrap|Line Numbers
  1. win32net.NetGroupAddMembers(server, group, level, members_data)
This is purposefully cryptic. You'll need to study the Win32 package and ensure that you know what you are doing with Windows sys/admin.

The thing is: I don't want to tell you something and have you break you machine.
Jul 24 '07 #2
bartonc
6,596 Recognized Expert Expert
Expand|Select|Wrap|Line Numbers
  1. win32net.NetGroupAddMembers(server, group, level, members_data)
This is purposefully cryptic. You'll need to study the Win32 package and ensure that you know what you are doing with Windows sys/admin.

The thing is: I don't want to tell you something and have you break you machine.
I can provide the missing information given a little background and more details of your environment. i.e. local machine vs domain, NT variant, etc.
Jul 24 '07 #3
pydou
6 New Member
I want to create user in win2k server, win 2k professional and win XP. if the user has already exists, I also need to be able to check and change its password.

now i want to change the IP related settings, could you please give me a function list or code sample?

thanks a lot
Jul 25 '07 #4
bartonc
6,596 Recognized Expert Expert
I want to create user in win2k server, win 2k professional and win XP. if the user has already exists, I also need to be able to check and change its password.

now i want to change the IP related settings, could you please give me a function list or code sample?

thanks a lot
From Python Programming on Win32 By Mark Hammond and Andy Robinson © 2000
Expand|Select|Wrap|Line Numbers
  1. # BatchUserCreate.py
  2. #
  3. # A sample administrative script to perform a batch 
  4. # creation of many users.
  5.  
  6. # Input to this program is a text file with one user per 
  7. # line.  Each line contains the new username and the
  8. # user's full name.
  9.  
  10. # Creates the new user, and a new share on the server 
  11. # for the user.  The new share is secure, and can only 
  12. # be accessed by the new user.
  13. import win32security, win32net, win32file, win32api
  14. import win32netcon, ntsecuritycon
  15. import os, sys, string
  16.  
  17. # The name of the server to use to create the user.
  18. serverName = None
  19.  
  20. # The logic for naming the home_drive assumes we have
  21. # a server name.  If we dont, get the current machine name.
  22. if serverName is None:
  23.     serverName = "\\\\" + win32api.GetComputerName()
  24.  
  25. # The root of each users personal directory.
  26. # This is a local reference to the directory where each 
  27. # personal directory is created.
  28. homeRoot = "C:\\Users"
  29.  
  30. def CreateUserAndShare(userName, fullName):
  31.     homeDir = "%s\\%s" % (serverName, userName)
  32.     # Create user data in information level 3 (PyUSER_INFO_3) format.
  33.     userData = {}
  34.     userData['name'] = userName
  35.     userData['full_name'] = fullName
  36.     userData['password'] = userName
  37.     userData['flags'] = win32netcon.UF_NORMAL_ACCOUNT | win32netcon.UF_SCRIPT
  38.     userData['priv'] = win32netcon.USER_PRIV_USER
  39.     userData['home_dir'] = homeDir
  40.     userData['home_dir_drive'] = "P:"
  41.     userData['primary_group_id'] = ntsecuritycon.DOMAIN_GROUP_RID_USERS
  42.     userData['password_expired'] = 1 # User must change password next logon.
  43.  
  44.     # Create the user
  45.     win32net.NetUserAdd(serverName, 3, userData)
  46.  
  47.     # Create the new directory, then the share
  48.     dirName = os.path.join(homeRoot, userName)
  49.     os.mkdir(dirName)
  50.     shareData = {}
  51.     shareData['netname'] = userName
  52.     shareData['type'] = win32netcon.STYPE_DISKTREE
  53.     shareData['path'] = dirName
  54.     shareData['max_uses'] = -1
  55.     # The security setting for the share.
  56.     sd = CreateUserSecurityDescriptor(userName)
  57.     shareData['security_descriptor'] = sd
  58.     # And finally create it.
  59.     win32net.NetShareAdd(serverName, 502, shareData)
  60.  
  61. # A utility function that creates an NT security object for a user.
  62. def CreateUserSecurityDescriptor(userName):
  63.     sidUser = win32security.LookupAccountName(serverName, userName)[0]
  64.     sd = win32security.SECURITY_DESCRIPTOR()
  65.  
  66.     # Create the "well known" SID for the administrators group
  67.     subAuths = ntsecuritycon.SECURITY_BUILTIN_DOMAIN_RID, \
  68.                ntsecuritycon.DOMAIN_ALIAS_RID_ADMINS
  69.     sidAdmins = win32security.SID(ntsecuritycon.SECURITY_NT_AUTHORITY, subAuths)
  70.  
  71.     # Now set the ACL, giving user and admin full access.
  72.     acl = win32security.ACL(128)
  73.     acl.AddAccessAllowedAce(win32file.FILE_ALL_ACCESS, sidUser)
  74.     acl.AddAccessAllowedAce(win32file.FILE_ALL_ACCESS, sidAdmins)
  75.  
  76.     sd.SetSecurityDescriptorDacl(1, acl, 0)
  77.     return sd
  78.  
  79. # Debug helper to delete our test accounts and shares.
  80. def DeleteUser(name):
  81.     try:    win32net.NetUserDel(serverName, name)
  82.     except win32net.error: pass
  83.  
  84.     try: win32net.NetShareDel(serverName, name)
  85.     except win32net.error: pass
  86.  
  87.     try: os.rmdir(os.path.join(homeRoot, name))
  88.     except os.error: pass
  89.  
  90. if __name__=='__main__':
  91.     import fileinput # Helper for reading files line by line
  92.     if len(sys.argv)<2:
  93.         print "You must specify an options file"
  94.         sys.exit(1)
  95.     if sys.argv[1]=="-delete":
  96.         for line in fileinput.input(sys.argv[2:]):
  97.             DeleteUser(string.split(line,",")[0])
  98.     else:
  99.         for line in fileinput.input(sys.argv[1:]):
  100.             userName, fullName = string.split(string.strip(line), ",")
  101.             CreateUserAndShare(userName, fullName)
  102.             print "Created", userName
  103.  
For further support on this, you'll need to buy the book.
Jul 27 '07 #5
pydou
6 New Member
thanks. very useful for my task.
Aug 8 '07 #6
bartonc
6,596 Recognized Expert Expert
thanks. very useful for my task.
You are welcome. I'm glad to know that you received the material.
Aug 8 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
4505
by: David Isal | last post by:
hi all, i'm new to python and i'm trying to build a python extension on win98, written in c++, with cygwin. but i keep having the same error message, and i didnt't find much resources on the web about it: >g++ -I/cygdrive/c/python22/include -c demomodule.cpp -o demomodule.o In file included from /cygdrive/c/python22/include/Python.h:62,...
2
1803
by: Bernhard Mulder | last post by:
I am using Python on Itanium Windows 64 (Server 2003) with a Win32 version. Is there a native version available or planned? Are testers needed for this platform? Windows 64 is a bit unusual in that "long" is not large enough to hold an address.
3
1815
by: Ryan Smith | last post by:
Hello All, I am new to the list and python community as well. I was wondering if anyone knows of any good python books emphasizing Windows 2000? I am a network engineer in an Active Directory environment and I have found serveral uses for python, and I need to find a book that emphasizes features of python 2.2 and programming in this type...
9
2354
by: Skip Montanaro | last post by:
I'd like to package up my typing watcher script in a bundled form (no separate Python install required) for use on Windows. (Un)fortunately, I don't have access to a Windows computer. Do any of the packaging tools (py2exe, MacMillan's Installer, etc) allow cross-platform bundling? Failing that, can I coax someone into building such a beast...
35
3037
by: Michael Kearns | last post by:
I've been using python to write a simple 'launcher' for one of our Java applications for quite a while now. I recently updated it to use python 2.4, and all seemed well. Today, one of my colleagues noted that on her machine the launcher would complain it was missing a DLL - msvcr71.dll However, there's a very grey area concerning the...
1
5358
by: abcd | last post by:
I am using Python to create a process on another computer. Both computers are on the same domain with admin privileges. On computer B I have a batch script which starts a python script. From computer A I am doing the following: import wmi w = wmi.WMI("1.2.3.4") p = w.new("Win32_Process") pid, retVal =...
8
2072
by: bhochstetler | last post by:
I am needing to build python 2.5 on Windows XP x64 Windows Server 2003 sp1 Platform SDK and am not finding anything documented on the process to use. Has anyone had any success with this? If so has anyone documented it? The documentation that resides in pcbuild/readme.txt is not helpful at all. Any help is greatly appreciated. Thanks Brad
2
1682
by: p.lavarre | last post by:
Let's suppose you get Python for Vista Windows today from http://www.python.org/download/. Should you then conclude that the tests: if platform.system() in ('Windows', 'Microsoft'): if not (platform.system() in ('Windows', 'Microsoft')): are now exactly what you should write for that 2.5.1 Python, when you must resort to os-specific...
4
2106
by: Joshua Kugler | last post by:
We've recently been doing some profiling on a project of ours. It runs quite fast on Linux but *really* bogs down on Windows 2003. We initially thought it was the simplejson libraries (we don't use the C extensions) but profiling proved otherwise. We have a function that does some runtime imports via calls to __import__. We ran 1000...
8
1842
by: Theo v. Werkhoven | last post by:
hi, In this code I read out an instrument during a user determined period, and save the relative time of the sample (since the start of the test) and the readback value in a csv file. #v+ from datetime import * from time import * from visa import *
0
7416
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7360
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7761
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5899
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4906
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3403
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3400
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1833
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
983
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.