I am new to the msdn library and masm.
After invoking NetUserAdd, I am trying to invoke NetLocalGroupAddMembers, but it requires type LPCWSTR for the group name. I think that is why my account I create is not visible and still does not appear after invoking NetLocalGroupAddMembers.
(I import a lot of files because my code is not complete and I know what I will be adding.)
Here is my code:
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
INCLUDE \masm32\include\msvcrt.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
INCLUDELIB \masm32\lib\msvcrt.lib
include \masm32\include\netapi32.inc
INCLUDELIB \masm32\lib\netapi32.lib
.data
lmi3 LOCALGROUP_MEMBERS_INFO_3 <>
domain byte "WIN-XXX\NAME",0
;conversion of domain to unicode
domainName BYTE 500 DUP(?)
; argument for NetUserAdd
error byte 50 dup(?)
; user name and password for new user
userPassword byte "NAME",0
userName byte "PWD",0
; will contain conversion of userPassword and userName to unicode
user byte 500 dup(?)
pwd byte 500 dup(?)
;structure declaration fo NetAddUser
account USER_INFO_1 <>
groupName BYTE "Users",0
; where I would place conversion of groupName
uniGroupName byte 200 DUP(?)
.code
main PROC
; convert to lpwstr (unicode)
invoke MultiByteToWideChar, CP_ACP, NULL, addr userName, -1, addr user, 500
invoke MultiByteToWideChar, CP_ACP, NULL, addr userPassword, -1, addr pwd, 500
mov account.usri1_name, offset user
mov account.usri1_password, offset pwd
; user access has to be User_Priv_User to call NetAddUser
mov account.usri1_priv, USER_PRIV_USER
mov account.usri1_home_dir, NULL
mov account.usri1_comment, NULL
mov account.usri1_flags, UF_SCRIPT
mov account.usri1_script_path, NULL
; 1 indicates user_info_1
invoke NetUserAdd, NULL, 1, addr account, offset error
; conversion to lpwstr
invoke MultiByteToWideChar, CP_ACP, NULL, addr domain, -1, addr domainName, 500
mov lmi3.lgrmi3_domainandname, offset domainAndName
; uniGroupName needs to be in LPCWSTR
invoke NetLocalGroupAddMembers,NULL,addr uniGroupName,3, offset lmi3,1
invoke ExitProcess,0
; end of procedure
main ENDP
; end of program
END main
You could either declare your group name string as
DW 'U','s','e','r','s',0
. Or if you'd rather do the conversion at runtime you can use thecrt_mbstowcs
function frommsvcrt
.Here's a small example program that tests both methods: