The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: KingB on November 18, 2005, 09:54:57 PM

Title: adding users to group using NetGroupAddUser ?
Post by: KingB on November 18, 2005, 09:54:57 PM
Dear all,

I'm writing a program which should add a user to a localgroup, nothing special, but we gotta learn don't we? ;-)

The problem is that the NetGroupAddUser() function is returning ERROR_IO_PENDING with the following code:


.686
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\netapi32.inc
include \masm32\include\user32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\netapi32.lib
includelib \masm32\lib\user32.lib

.DATA

uservar db "USERNAME",0
groupn  db "test",0
allok   db "User has been added successfully!",0
.DATA?

userbuf db 512 dup (?)

.CODE
start:

invoke GetEnvironmentVariable,addr uservar,addr userbuf,sizeof userbuf
.IF eax!=0
   
    invoke NetGroupAddUser,NULL,addr groupn,addr userbuf
    .IF eax==ERROR_SUCCESS
        invoke MessageBoxA,NULL,addr uservar,addr allok,MB_OK
    .ENDIF
.ENDIF
invoke ExitProcess,0

end start     


i really don't see what i'm missing here: local user, add to "test" (localgroup) on the local computer (NULL). How hard could it be?
Can anyone please explain what is going wrong since i'm getting really sick of this. This is supposed to become a part of a loginscript for a large domain who all should be added to the localgroup on their computers...

Thanks in advance for all your trouble!

Kind regards,

Bert
Title: Re: adding users to group using NetGroupAddUser ?
Post by: sluggy on November 19, 2005, 10:30:44 AM
ERROR_IO_PENDING is not one of the listed error codes returned by that function - a lot of error codes have a different name but the same value. Check this link (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netmgmt/netmgmt/netgroupadduser.asp) to see if you are actually getting one of those errors.
Also, hve you verified with a debugger, or at least a message box, the value being returned by GetEnvironmentVariable into userbuf? And NetGroupAddUser requires that its input be unicode, not ansi.

Title: Re: adding users to group using NetGroupAddUser ?
Post by: KingB on November 19, 2005, 03:42:49 PM
Hi Sluggy,

Thanks for your reply!

first i know for sure that the errorcode is correct: Ollydbg shows this error code, eax contains the same value as well.
second, i've tried using unicode strings as well, but this doesn't matter, i still get the same errorcode.

I've used a temporarily workaround: cmd.exe "/c net localgroup test <username> /add"
but the code should work directly as well...