我是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
答案 0 :(得分:1)
您可以将群组名称字符串声明为DW 'U','s','e','r','s',0
。或者,如果您希望在运行时进行转换,则可以使用crt_mbstowcs
中的msvcrt
函数。
这是一个测试两种方法的小例子程序:
.686p
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\msvcrt.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\msvcrt.lib
.data
; %s for ASCII, %S for wide strings
format db "original: %s, converted: %S",13,10,0
; An ASCII string that we'll convert at runtime
original db "Foobar",0
converted dw 32 dup(0)
; A statically created wide string
testws dw 'T','e','s','t',13,10,0
.code
main PROC
; Print our statically created wide string
invoke crt_wprintf, ADDR testws
; Converts the characters in 'original' into wide characters and stores them
; in 'converted'.
invoke lstrlen,ADDR original
invoke crt_mbstowcs, ADDR converted, ADDR original, eax
; Print both the original and converted string, then exit the program.
invoke crt_printf, ADDR format, ADDR original, ADDR converted
invoke ExitProcess, 0
main ENDP
END main