Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80524

Re: Need some help with NetGroupAddUser

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.014
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'error:': 0.07; 'subject:help': 0.08; 'fullname': 0.09; 'newly': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'skip:# 30': 0.09; 'used.': 0.09; 'python': 0.11; 'def': 0.12; 'message- id:@post.gmane.org': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'thanks,': 0.17; 'code.': 0.18; 'all,': 0.19; 'programming': 0.22; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'replace': 0.24; 'question': 0.24; "i've": 0.25; 'header:X-Complaints-To:1': 0.27; 'tried': 0.27; 'appreciated.': 0.29; 'code': 0.31; "skip:' 10": 0.31; '(on': 0.31; 'piece': 0.31; 'subject:some': 0.31; 'username': 0.31; 'writes:': 0.31; 'worked': 0.33; 'could': 0.34; 'subject:with': 0.35; 'created': 0.35; 'skip:u 20': 0.35; 'add': 0.35; 'format.': 0.36; 'next': 0.36; 'charset:us-ascii': 0.36; "i'll": 0.36; 'should': 0.36; 'level': 0.37; 'needed': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'called': 0.40; 'users': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'skip:n 30': 0.60; 'hope': 0.61; 'new': 0.61; 'back': 0.62; 'information': 0.63; 'name': 0.63; 'soon': 0.63; 'skip:n 10': 0.64; 'subject:Need': 0.64; 'here': 0.66; 'sample': 0.67; 'skip:w 30': 0.69; 'guests,': 0.84; 'received:in': 0.84; 'subject:skip:N 10': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Jaimin Ajmeri <jaiminajmeri@gmail.com>
Subject Re: Need some help with NetGroupAddUser
Date Tue, 11 Nov 2014 04:30:46 +0000 (UTC)
References <200212022206.gB2M6oCB006981@smtp-server1.tampabay.rr.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host sea.gmane.org
User-Agent Loom/3.14 (http://gmane.org/)
X-Loom-IP 203.199.198.252 (Mozilla/5.0 (Windows NT 6.1; rv:33.0) Gecko/20100101 Firefox/33.0)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15662.1415715005.18130.python-list@python.org> (permalink)
Lines 73
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1415715005 news.xs4all.nl 2918 [2001:888:2000:d::a6]:39594
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:80524

Show key headers only | View raw


 <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 


Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Need some help with NetGroupAddUser Jaimin Ajmeri <jaiminajmeri@gmail.com> - 2014-11-11 04:30 +0000

csiph-web