News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

adding users to group using NetGroupAddUser ?

Started by KingB, November 18, 2005, 09:54:57 PM

Previous topic - Next topic

KingB

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

sluggy

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 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.


KingB

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...