The following samples show how to manage Windows accounts with COM. There are two samples, one using DISPATCH and one using the AdsHlp.inc library by José Roca. The samples are helpfull, if you like to use Microsoft VBS samples. I prefer the DISPATCH sample, because it results in a smaller executable.

Sample with ADsHlp.inc:
Code:
' Functions to manipulate local accounts using ADs
'-------------------------------------------------------------------
#INCLUDE "AdsHlp.inc" ' library by José Roca

DECLARE Function ADs_CreateUser (strComputer AS STRING, strUser AS STRING, strPassword AS STRING) AS LONG
DECLARE FUNCTION ADs_AddUserToGroup (strComputer AS STRING, strUser AS STRING, strGroup AS STRING) AS LONG
DECLARE FUNCTION ADs_DeleteUser (strComputer AS STRING, strUser AS STRING) AS LONG
DECLARE FUNCTION ADs_RemoveUserFromGroup (strComputer AS STRING, strUser AS STRING, strGroup AS STRING) AS LONG
DECLARE FUNCTION GenName (nLength AS INTEGER, nSymbol AS INTEGER) AS STRING
DECLARE FUNCTION GetHostName() AS STRING

Function ADs_CreateUser (strComputer AS STRING, strUser AS STRING, strPassword AS STRING) AS LONG
  LOCAL hr AS LONG
  LOCAL colAccounts AS IADsContainer
  LOCAL objUser AS IADsUser
  LOCAL strADsPath AS STRING

  strADsPath = UCODE$("WinNT://" & strComputer & "")
  hr = ADsGetObject(STRPTR(strADsPath), $IID_IADsContainer, colAccounts)
  IF hr <> 0 THEN
    FUNCTION = hr
    EXIT FUNCTION
  END IF

  objUser = colAccounts.Create(UCODE$("user"), UCODE$(strUser))
  IF ISFALSE(ISOBJECT(objUser)) THEN
    FUNCTION = -1
    EXIT FUNCTION
  END IF

  objUser.SetPassword(UCODE$(strPassword))
  IF OBJRESULT <> 0 THEN
    FUNCTION = -2
  END IF
  
  objUser.SetInfo
  IF OBJRESULT <> 0 THEN
    FUNCTION = -3
  END IF
  
  SET objUser = NOTHING
  SET colAccounts = NOTHING
  
  FUNCTION = 0

END FUNCTION


FUNCTION ADs_AddUserToGroup (strComputer AS STRING, strUser AS STRING, strGroup AS STRING) AS LONG
  LOCAL hr AS LONG
  LOCAL colAccounts AS IADsContainer
  LOCAL objGroup AS IADsGroup
  LOCAL objUser AS IADsUser
  LOCAL strADsPath AS STRING

  strADsPath = UCODE$("WinNT://" & strComputer & "")
  hr = ADsGetObject(STRPTR(strADsPath), $IID_IADsContainer, colAccounts)
  IF hr <> 0 THEN
    FUNCTION = hr
    EXIT FUNCTION
  END IF

  objUser = colAccounts.GetObject(UCODE$("user"), UCODE$(strUser))
  IF ISFALSE(ISOBJECT(objUser)) THEN 
    FUNCTION = -1
    EXIT FUNCTION
  END IF
  
  objGroup = colAccounts.GetObject(UCODE$("group"), UCODE$(strGroup))
  IF ISFALSE(ISOBJECT(objGroup)) THEN 
    FUNCTION = -2
    EXIT FUNCTION
  END IF
  
  IF objGroup.IsMember(objUser.ADsPath) = 0 THEN
    objGroup.Add(objUser.ADsPath)
  END IF

  IF objGroup.IsMember(objUser.ADsPath) = -1 THEN
    FUNCTION = 0
  ELSE
    FUNCTION = -3
  END IF
  
  SET objUser = NOTHING
  SET objGroup = NOTHING
  SET colAccounts = NOTHING

END FUNCTION


FUNCTION ADs_RemoveUserFromGroup (strComputer AS STRING, strUser AS STRING, strGroup AS STRING) AS LONG
  LOCAL hr AS LONG
  LOCAL colAccounts AS IADsContainer
  LOCAL objGroup AS IADsGroup
  LOCAL objUser AS IADsUser
  LOCAL strADsPath AS STRING

  strADsPath = UCODE$("WinNT://" & strComputer & "")
  hr = ADsGetObject(STRPTR(strADsPath), $IID_IADsContainer, colAccounts)
  IF hr <> 0 THEN
    FUNCTION = hr
    EXIT FUNCTION
  END IF

  objUser = colAccounts.GetObject(UCODE$("user"), UCODE$(strUser))
  IF ISFALSE(ISOBJECT(objUser)) THEN 
    FUNCTION = -1
    EXIT FUNCTION
  END IF
  
  objGroup = colAccounts.GetObject(UCODE$("group"), UCODE$(strGroup))
  IF ISFALSE(ISOBJECT(objGroup)) THEN 
    FUNCTION = -2
    EXIT FUNCTION
  END IF
  
  IF objGroup.IsMember(objUser.ADsPath) = -1 THEN
    objGroup.Remove(objUser.ADsPath)
  END IF

  IF objGroup.IsMember(objUser.ADsPath) = 0 THEN
    FUNCTION = 0
  ELSE
    FUNCTION = -3
  END IF
  
  SET objUser = NOTHING
  SET objGroup = NOTHING
  SET colAccounts = NOTHING

END FUNCTION


FUNCTION ADs_DeleteUser (strComputer AS STRING, strUser AS STRING) AS LONG
  LOCAL hr AS LONG
  LOCAL objComp AS IADsContainer
  LOCAL strADsPath AS STRING

  strADsPath = UCODE$("WinNT://" & strComputer & "")
  hr = ADsGetObject(STRPTR(strADsPath), $IID_IADsContainer, objComp)
  IF hr <> 0 THEN
    FUNCTION = hr
    EXIT FUNCTION
  END IF
  
  objComp.Delete (UCODE$("user"), UCODE$(strUser))

  IF OBJRESULT = 0 THEN
    FUNCTION = 0
  ELSE
    FUNCTION = -1
  END IF
  
  SET objComp = NOTHING

END FUNCTION


FUNCTION GenName (nLength AS INTEGER, nSymbol AS INTEGER) AS STRING
  dim i as integer, j AS INTEGER, iMax as INTEGER
  DIM s as STRING, sSymbols AS STRING

  sSymbols = "#!+-_="
  
  IF nLength = 0 THEN nLength = 1
  nLength = nLength +3
  iMax = nLength \ 3
  
  RANDOMIZE TIMER
  
  FOR i = 1 TO iMax
    s = s & CHR$(RND(65, 90))
    s = s & CHR$(RND(97, 122))
    s = s & CHR$(RND(48, 57))
    IF nSymbol > 0 THEN
      j = RND(0, 12)
      IF j > 0 AND j <= 6 THEN
        s = s & MID$(sSymbols,j,1)
      END IF
    END IF 
  NEXT

  FUNCTION = LEFT$(s, nLength)
END FUNCTION

FUNCTION GetHostName() AS STRING

  LOCAL szTmp AS ASCIIZ * %MAX_PATH
  LOCAL sTmp  AS STRING

  HOST NAME TO sTmp
  sTmp = TRIM$(sTmp)
  IF LEN(sTmp) = 0 THEN
    GetComputerName szTmp, 48
    sTmp = szTmp
  END IF
  FUNCTION = LCASE$(sTmp)

END FUNCTION
Sample using DISPATCH:
Code:
' Functions to manipulate local accounts using ADs
'-------------------------------------------------------------------

$IID_IADsContainer = GUID$("{001677D0-FD16-11CE-ABC4-02608C9E7553}")

DECLARE FUNCTION ADsGetObject LIB "Activeds.dll" ALIAS "ADsGetObject" ( _
  BYVAL lpszPathName AS DWORD _                          ' __in  LPCWSTR lpszPathName
  , BYREF riid AS GUID _                                 ' __in  REFIID  riid
  , BYREF ppObject AS ANY _                              ' __out VOID**  ppObject
  ) AS LONG                                              ' HRESULT

DECLARE Function ADs_CreateUser (strComputer AS STRING, strUser AS STRING, strPassword AS STRING) AS LONG
DECLARE FUNCTION ADs_AddUserToGroup (strComputer AS STRING, strUser AS STRING, strGroup AS STRING) AS LONG
DECLARE FUNCTION ADs_DeleteUser (strComputer AS STRING, strUser AS STRING) AS LONG
DECLARE FUNCTION ADs_RemoveUserFromGroup (strComputer AS STRING, strUser AS STRING, strGroup AS STRING) AS LONG
DECLARE FUNCTION GenName (nLength AS INTEGER, nSymbol AS INTEGER) AS STRING
DECLARE FUNCTION GetHostName() AS STRING
DECLARE FUNCTION CheckHostName(sCompName AS STRING) AS STRING

Function ADs_CreateUser (strComputer AS STRING, strUser AS STRING, strPassword AS STRING) AS LONG
  LOCAL hr AS LONG
  LOCAL colAccounts AS Dispatch
  LOCAL objUser AS Dispatch
  LOCAL vFilter, vUser, vPassword AS VARIANT
  LOCAL strADsPath AS STRING

  vFilter = "user" : vUser = strUser : vPassword = strPassword
  
  strADsPath = UCODE$("WinNT://" & strComputer & "")
  hr = ADsGetObject(STRPTR(strADsPath), $IID_IADsContainer, colAccounts)
  IF hr <> 0 THEN
    FUNCTION = hr
    EXIT FUNCTION
  END IF
  
  OBJECT CALL colAccounts.Create(vFilter, vUser) TO objUser
  IF ISFALSE(ISOBJECT(objUser)) THEN
    FUNCTION = -1
    EXIT FUNCTION
  END IF

  OBJECT CALL objUser.SetPassword(vPassword)
  IF ISFALSE(ISOBJECT(objUser)) THEN 
    FUNCTION = -2
    EXIT FUNCTION
  END IF
  
  OBJECT CALL objUser.SetInfo
  IF ISFALSE(ISOBJECT(objUser)) THEN
    FUNCTION = -3
    EXIT FUNCTION
  END IF
  
  SET objUser = NOTHING
  SET colAccounts = NOTHING
  
  FUNCTION = 0

END FUNCTION

FUNCTION ADs_AddUserToGroup (strComputer AS STRING, strUser AS STRING, strGroup AS STRING) AS LONG
  LOCAL hr AS LONG
  LOCAL colAccounts AS Dispatch
  LOCAL objGroup AS Dispatch
  LOCAL objUser AS Dispatch
  LOCAL vFilter, vUser, vGroup, vADsPath, vIsMember AS VARIANT
  LOCAL strADsPath AS STRING

  strADsPath = UCODE$("WinNT://" & strComputer & "")
  hr = ADsGetObject(STRPTR(strADsPath), $IID_IADsContainer, colAccounts)
  IF hr <> 0 THEN
    FUNCTION = hr
    EXIT FUNCTION
  END IF

  vUser = strUser : vGroup = strGroup

  vFilter = "user"
  OBJECT CALL colAccounts.GetObject(vFilter, vUser) TO objUser
  IF ISFALSE(ISOBJECT(objUser)) THEN 
    FUNCTION = -1
    EXIT FUNCTION
  END IF

  vFilter = "group"
  OBJECT CALL colAccounts.GetObject(vFilter, vGroup) TO objGroup
  IF ISFALSE(ISOBJECT(objGroup)) THEN 
    FUNCTION = -2
    EXIT FUNCTION
  END IF
  
  OBJECT GET objUser.ADsPath TO vADsPath
  
  OBJECT CALL objGroup.IsMember(vADsPath) TO vIsMember
  IF ISFALSE VARIANT#(vIsMember) THEN
    OBJECT CALL objGroup.Add(vADsPath)
  END IF
  
  OBJECT CALL objGroup.IsMember(vADsPath) TO vIsMember
  IF NOT ISFALSE VARIANT#(vIsMember) THEN
    FUNCTION = 0
  ELSE
    FUNCTION = -3
  END IF
  
  SET objUser = NOTHING
  SET objGroup = NOTHING
  SET colAccounts = NOTHING
  
END FUNCTION


FUNCTION ADs_RemoveUserFromGroup (strComputer AS STRING, strUser AS STRING, strGroup AS STRING) AS LONG
  LOCAL hr AS LONG
  LOCAL colAccounts AS Dispatch
  LOCAL objGroup AS Dispatch
  LOCAL objUser AS Dispatch
  LOCAL vFilter, vUser, vGroup, vADsPath, vIsMember AS VARIANT
  LOCAL strADsPath AS STRING

  strADsPath = UCODE$("WinNT://" & strComputer & "")
  hr = ADsGetObject(STRPTR(strADsPath), $IID_IADsContainer, colAccounts)
  IF hr <> 0 THEN
    FUNCTION = hr
    EXIT FUNCTION
  END IF

  vUser = strUser : vGroup = strGroup

  vFilter = "user"
  OBJECT CALL colAccounts.GetObject(vFilter, vUser) TO objUser
  IF ISFALSE(ISOBJECT(objUser)) THEN 
    FUNCTION = -1
    EXIT FUNCTION
  END IF

  vFilter = "group"
  OBJECT CALL colAccounts.GetObject(vFilter, vGroup) TO objGroup
  IF ISFALSE(ISOBJECT(objGroup)) THEN 
    FUNCTION = -2
    EXIT FUNCTION
  END IF
  
  OBJECT GET objUser.ADsPath TO vADsPath

  OBJECT CALL objGroup.IsMember(vADsPath) TO vIsMember
  IF NOT ISFALSE VARIANT#(vIsMember) THEN
    OBJECT CALL objGroup.Remove(vADsPath)
  END IF
  
  OBJECT CALL objGroup.IsMember(vADsPath) TO vIsMember
  IF ISFALSE VARIANT#(vIsMember) THEN
    FUNCTION = 0
  ELSE
    FUNCTION = -3
  END IF
  
  SET objUser = NOTHING
  SET objGroup = NOTHING
  SET colAccounts = NOTHING
  
END FUNCTION


FUNCTION ADs_DeleteUser (strComputer AS STRING, strUser AS STRING) AS LONG
  LOCAL hr AS LONG
  LOCAL objComp AS Dispatch
  LOCAL vFilter, vUser AS VARIANT
  LOCAL strADsPath AS STRING

  vFilter = "user" : vUser = strUser
  
  strADsPath = UCODE$("WinNT://" & strComputer & "")
  hr = ADsGetObject(STRPTR(strADsPath), $IID_IADsContainer, objComp)
  IF hr <> 0 THEN
    FUNCTION = hr
    EXIT FUNCTION
  END IF

  OBJECT CALL objComp.Delete (vFilter, vUser)
  IF OBJRESULT = 0 THEN
    FUNCTION = 0
  ELSE
    FUNCTION = -1
  END IF

  SET objComp = NOTHING

END FUNCTION


FUNCTION GenName (nLength AS INTEGER, nSymbol AS INTEGER) AS STRING
  dim i as integer, j AS INTEGER, iMax as INTEGER
  DIM s as STRING, t as string, sSymbols AS STRING

  sSymbols = "`[email protected]#$%^&*()_+-={}|[]\:;<>?,./"
  
  IF nLength = 0 THEN nLength = 1
  nLength = nLength +3
  iMax = nLength \ 3
  
  RANDOMIZE TIMER
  
  FOR i = 1 TO iMax
    s = s & CHR$(RND(65, 90))
    s = s & CHR$(RND(97, 122))
    s = s & CHR$(RND(48, 57))
    IF nSymbol > 0 THEN
      j = RND(0, 32)
      IF j > 0 AND j <= 30 THEN
        s = s & MID$(sSymbols,j,1)
      END IF
    END IF 
  NEXT

  FUNCTION = LEFT$(s, nLength)
END FUNCTION


FUNCTION CheckHostName(sCompName AS STRING) AS STRING
  sCompName = TRIM$(sCompName)
  IF LEN(sCompName) = 0 OR sCompName = "." THEN
    sCompName = TRIM$(LCASE$(ENVIRON$("COMPUTER")))
    IF LEN(sCompName) = 0 THEN
      sCompName = GetHostName()
    END IF
    IF INSTR(sCompName, ".") THEN
      sCompName = LEFT$(sCompName, INSTR(sCompName, ".") -1)
    END IF
  END IF
  FUNCTION = sCompName
END FUNCTION


FUNCTION GetHostName() AS STRING

  LOCAL szTmp AS ASCIIZ * %MAX_PATH
  LOCAL sTmp  AS STRING

  HOST NAME TO sTmp
  sTmp = TRIM$(sTmp)
  IF LEN(sTmp) = 0 THEN
    GetComputerName szTmp, 48
    sTmp = szTmp
  END IF
  FUNCTION = LCASE$(sTmp)

END FUNCTION