Sign in to follow this  
Followers 0
HockeyFan

Local XP User account creation

3 posts in this topic

I found an example of this script on the forum, but it's not working for me. Can someone give me some advice on why this script fails when adding the user account to the Administrator's group? I keep getting the error message "line -1: Error: The requested action with this object has failed".

Const $ADS_UF_DONT_EXPIRE_PASSWD = 0X10000
 Const $ADS_UF_PASSWD_CANT_CHANGE = 0X40
 $UserName = $UsernameNoWS
 $Password = $PasswordRead
 $strComputer = @ComputerName
 $strGroup = "Administrators"
 
; Check if account exists .. if not create it 
 $objUser = ObjGet("WinNT://" & $strComputer & "/" & $UserName)
 If @Error then 
  $colAccounts = ObjGet("WinNT://" & $strComputer & "")
  $objUser = $colAccounts.Create("user", $UserName)
  $objUser.SetPassword ($Password)
  $objUser.Put ("Fullname", $FullName)
  $objUser.Put ("Description", $Description)
  $objUser.SetInfo
  FileWriteLine($Log, @YEAR & "/" & @MON & "/" & @MDAY & "-" & @HOUR & ":" & @MIN & ":" & @SEC & ' Account "' & $UserName & '" created.' & @CRLF)
 EndIf</P> <P>; Read current settings and Bitor to ensure the "Don't expire password swith is on" 
 $oldFlags = $objUser.Get("UserFlags")
 $newFlags = BitOR($oldFlags,$ADS_UF_DONT_EXPIRE_PASSWD)
 $objUser.Put ("UserFlags", $newFlags);expire the password
 $objUser.SetInfo
 
;Add User to group 
 $objGroup = ObjGet("WinNT://" & $strComputer & "/" & $strGroup)
 $objGroup.Add("WinNT://" & $strComputer & "/" & $UserName)

FYI...I'm just trying to script adding a local user to the PC and join them to the Administrator's group. NO Domain at this point.

Any help would be greatly appreciated! :mellow:

Share this post


Link to post
Share on other sites



Hello!

Don't see how your code does so, but you may try with API's, like this;

_NetAPI_LocalGroupAddMember($UserName, $strGroup)  
Sleep (2000)
Exit

Func _NetAPI_LocalGroupAddMember($sAccount, $sGroup, $sServer = '')
    Local $twUser = DllStructCreate("wchar["& StringLen($sAccount)+1 &"]")
    Local $tpUser = DllStructCreate("ptr")
    DllStructSetData($twUser, 1, $sAccount)
    DllStructSetData($tpUser, 1, DllStructGetPtr($twUser))
    Local $aRet = DllCall("netapi32.dll", "int", "NetLocalGroupAddMembers", _
        "wstr", $sServer, "wstr", $sGroup, "int", 3, "ptr", DllStructGetPtr($tpUser), "int", 1 )
    If $aRet[0] Then Return SetError(1, $aRet[0], False)
    Return True
EndFunc    ;_NetAPI_LocalGroupAddMember

Hope that will help

Thierry

Share this post


Link to post
Share on other sites

Nevermind... :(

Problem ended up being with the computer I was using to test the script. I've changed computers and no longer have this problem. :mellow:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0