Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80527 > unrolled thread
| Started by | MRAB <python@mrabarnett.plus.com> |
|---|---|
| First post | 2014-11-11 15:04 +0000 |
| Last post | 2014-11-11 15:04 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Need some help with NetGroupAddUser MRAB <python@mrabarnett.plus.com> - 2014-11-11 15:04 +0000
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2014-11-11 15:04 +0000 |
| Subject | Re: Need some help with NetGroupAddUser |
| Message-ID | <mailman.15665.1415718268.18130.python-list@python.org> |
On 2014-11-11 04:30, Jaimin Ajmeri wrote:
> <kcollins15 <at> cfl.rr.com> writes:
>
>>
>> New B question -- Need help with win32net.NetGroupAddUser. I used Mark
> Hammond
>> sample code to create a new user from his book Python Programming on Win32. I
>> then added one line to add the newuser to a group.
>> 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)
>> win32net.NetGroupAddUser(serverName, "Administrator", userName)
>>
>> This is my error:
>> pywintypes.api_error: (2220, 'NetGroupAddUser', 'The group name could not be
>> found.')
>> What should I be using for the groupname parameter, I've tried them all,
>> Administrator, Guests, Users ext.... Any help will be greatly appreciated.
>> Thanks,
>> kc
>>
>>
>
> Hello kcollins15,
>
> Just try this.....
>
> import win32api
> import win32net
>
> ###############################
>
> Code to create user goes here
>
> ###############################
>
> ######################################################################
>
> # Code to add created user to a group (on a local machine)
>
> serverName = "\\\\" + win32api.GetComputerName()
> domain = win32api.GetDomainName()
> data = [{"domainandname" : domain + "\\TestUser"}]
> print "Adding...."
> win32net.NetLocalGroupAddMembers(serverName,"Users",3,data)
> print "Added Successfully !!"
>
> ######################################################################
>
> This is working piece of code. It worked for me, I needed to add newly
> created user to the group called "Users".
>
> Just replace "Users" with "Administrator".
>
> I'll get back soon on how and when NetGroupAddUser() should be used.
>
> Hope it helps...!
> Jaimin Ajmeri
>
I think you're replying to a post that's more than 10 years old!
Back to top | Article view | comp.lang.python
csiph-web