Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.019 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'error:': 0.07; 'subject:help': 0.08; 'fullname': 0.09; 'newly': 0.09; 'skip:# 30': 0.09; 'used.': 0.09; 'python': 0.11; 'def': 0.12; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; '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; 'post': 0.26; 'header:In-Reply- 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; 'received:84': 0.35; 'add': 0.35; 'format.': 0.36; 'next': 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; '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; "you're": 0.61; 'back': 0.62; 'information': 0.63; 'name': 0.63; 'soon': 0.63; 'skip:n 10': 0.64; 'subject:Need': 0.64; 'more': 0.64; 'here': 0.66; 'sample': 0.67; 'skip:w 30': 0.69; 'guests,': 0.84; 'subject:skip:N 10': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=IfMJWAaa c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=aoAcgTy3oA8A:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=ayC55rCoAAAA:8 a=jVv6-Ff_m94iSGuU7MMA:9 a=QEXdDO2ut3YA:10 X-AUTH: mrabarnett:2500 Date: Tue, 11 Nov 2014 15:04:18 +0000 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Need some help with NetGroupAddUser References: <200212022206.gB2M6oCB006981@smtp-server1.tampabay.rr.com> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 74 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415718268 news.xs4all.nl 2852 [2001:888:2000:d::a6]:50687 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80527 On 2014-11-11 04:30, Jaimin Ajmeri wrote: > 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!