我是 msdn 库和 masm 的新手。
调用 NetUserAdd 后,我尝试调用 NetLocalGroupAddMembers,但它需要类型 LPCWSTR 作为组名。我认为这就是为什么我创建的帐户不可见并且在调用 NetLocalGroupAddMembers 后仍然不出现的原因。
(我导入了很多文件,因为我的代码不完整,而且我知道要添加什么。)
这是我的代码:
.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