Declare Function NetLocalGroupAdd Lib "netapi32.dll" _ Alias "NetLocalGroupAdd" ( _ ByVal servername As Long, _ ByVal level As Long, _ ByVal buf As Long, _ ByRef parm_err As Long) As Long
NetLocalGroupAdd создает локальную группу пользователей
В успешном случае функция возвращает NERR_Success. В случае ошибки функция возвращает коды ошибок:
ERROR_ACCESS_DENIED | The caller does not have the appropriate access to complete the operation. |
ERROR_ALIAS_EXISTS | The specified local group already exists. This error is returned if the group name member in the structure pointed to by the buf parameter is already in use as an alias. |
ERROR_INVALID_LEVEL | A level parameter is invalid. |
ERROR_INVALID_PARAMETER | A parameter is incorrect. This error is returned if one or more of the members in the structure pointed to by the buf parameter is invalid. |
NERR_GroupExists | The group name exists. This error is returned if the group name member in the structure pointed to by the buf parameter is already in use as a group name. |
NERR_InvalidComputer | The computer name is invalid. |
NERR_NotPrimary | The operation is allowed only on the primary domain controller of the domain.|
NERR_UserExists | The user name exists. This error is returned if the group name member in the structure pointed to by the buf parameter is already in use as a user name. |
0 | Имя локальной группы. Параметр buf использует структуру LOCALGROUP_INFO |
1 | Имя локальной группы и комментарий для этой группы. Параметр buf использует структуру LOCALGROUP_INFO1 |
' Создадим локальную группу под именем group и с комментарием Comment
Private Sub Command1_Click()
Dim lRetVal As Long ' возвращаемое значение
Dim hKey As Long ' дескриптор открытого ключа
Dim vValue As Variant
Dim Name As Group_Info_1 ' настройки для локальной группы (имя и комментарий)
Dim bServer() As Byte ' строка с завершающим нулевым символом, содержащая имя сервера
Dim sNameLen As String 'setting of variables for length
Dim sCommentLen As String ' of local group name and
' comment for ANSI to Unicode
' conversion
' ---------------------------------------------
' Conversion of 1 bit ansi VB output to the 2 bit
' unicode required by NT/W2K
' ---------------------------------------------
sNameLen = Len("Group")
sCommentLen = Len("Comment")
Do While Not sNameLen = 0
Name.lgrpi1_name = Mid("Group", sNameLen, 1) & _
vbNullChar & Name.lgrpi1_name
sNameLen = sNameLen - 1
Loop
Do While Not sCommentLen = 0
Name.lgrpi1_comment = Mid("Comment", sCommentLen, 1) & _
vbNullChar & Name.lgrpi1_comment
sCommentLen = sCommentLen - 1
Loop
bServer = "\\ServerName" & vbNullChar 'null terminated
'string
' ---------------------------------------------
' Local Group Creation
' ---------------------------------------------
lRetVal = NetLocalGroupAdd(bServer(0), 1, Name, 0)
MsgBox "Операция завершена"
End Sub