Jump to content
Sign in to follow this  
PcExpert

Create useraccount

Recommended Posts

PcExpert

Hi all,

I was wondering if its possible to make 2 inputboxes where the user specifies name and password. And the program sets that account as the autologon account. I found this:

http://wwtw.autoitscript.com/forum/index.p...;hl=create+user

But that only lets you choose a username not a passwords.

Thanks in advance!

Share this post


Link to post
Share on other sites
PcExpert

Somebody, please

Share this post


Link to post
Share on other sites
Jos

don;t know what post you tried to link to but this script will create a local account ..

Just add the Inputboxes.

; Init objects
$UserName = 'Fred'
$Password = 'Wil"ma'
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Install a custom error handler 
$strComputer = @ComputerName
$colAccounts = ObjGet("WinNT://" & $strComputer & "")
;$objGroup = ObjGet("WinNT://" & $strComputer & "/Users,group")
; Read in lines of text until the EOF is reached
$objUser = $colAccounts.Create("user", $UserName)
$objUser.SetPassword ($Password)
$objUser.Put ("Fullname", "Test User")
$objUser.Put ("Description", "Test User description")
$objUser.SetInfo
;Add user to group 
;$objGroup.Add($objUser.ADsPath)
;
;
; This is my custom error handler 
Func MyErrFunc() 
   $HexNumber=hex($oMyError.number,8) 
   Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
                "Number is: " & $HexNumber & @CRLF & _
                "Linenbr is: " & $oMyError.scriptline  & @CRLF & _
                "Description is: " & $oMyError.description  & @CRLF & _
                "Windescription is: " & $oMyError.windescription ) 

   SetError(1) ; something to check for when this function returns 
Endfunc
Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
PcExpert

Thanks JdeB! How to delete the account if everything is finished?

Share this post


Link to post
Share on other sites
Jos

Thanks JdeB! How to delete the account if everything is finished?

Here is a complete example to Create/Rename/Delete an Local account:

; Init objects
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Install a custom error handler 
$UserName = 'Fred'
$Password = 'Wilma123'
$strComputer = @ComputerName
;***********************
;Create UserID
$colAccounts = ObjGet("WinNT://" & $strComputer & "")
$objUser = $colAccounts.Create("user", $UserName)
$objUser.SetPassword ($Password)
$objUser.Put ("Fullname", "Test User")
$objUser.Put ("Description", "Test User description")
$objUser.Put ("PasswordExpired", 1)  ;expire the password
$objUser.SetInfo
;***********************
;Add User to group 
;$objGroup = ObjGet("WinNT://" & $strComputer & "/Administrators,group")
;$objGroup.Add($objUser.ADsPath)
;***********************
; Rename User
$colAccounts = ObjGet("WinNT://" & $strComputer & "")
$objUser = $colAccounts.Create("user", $UserName)
$OldUser = "Fred"
$NewUser = "Fredrenamed"
$oUser = ObjGet("WinNT://" & @ComputerName & "/" & $OldUser & ",user")
$oComputer = ObjGet("WinNT://" & @ComputerName)
$oNewUser = $oComputer.MoveHere($oUser.ADsPath, $NewUser)
                                                                    MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$oNewUser' & @lf & @lf & 'Return:' & @lf & $oNewUser & @lf & @lf & '@Error:' & @lf & @Error) ;### Debug MSGBOX
; Delete User
$colAccounts = ObjGet("WinNT://" & $strComputer & "")
$objUser = $colAccounts.Delete("user", $NewUser)


Func MyErrFunc() 
   $HexNumber=hex($oMyError.number,8) 
   Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
                "Number is: " & $HexNumber & @CRLF & _
                "Linenbr is: " & $oMyError.scriptline  & @CRLF & _
                "Description is: " & $oMyError.description  & @CRLF & _
                "Windescription is: " & $oMyError.windescription ) 

   SetError(1) ; something to check for when this function returns 
Endfunc
Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
star2

one silly question

can I get a list of user names?


[quote]Baby you're all that I want, When you're lyin' here in my armsI'm findin' it hard to believe, We're in heavenAnd love is all that I need , And I found it there in your heartIt isn't too hard to see, We're in heaven .Bryan Adams[/quote].............................................................................[u]AUTOIT[/u]

Share this post


Link to post
Share on other sites
Jos

one silly question

can I get a list of user names?

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Install a custom error handler 
Local $objDomain = ObjGet("WinNT://" & @ComputerName & "" )
;Set objDomain = GetObject("WinNT://domainname,domain")
Dim $filter[2] = ["user"]
$objDomain.Filter = $filter

For $aUser In $objDomain
   ConsoleWrite($aUSer.Name & "|" & $aUSer.Description & @LF)
Next

;COM Error function
Func ComError()
    If IsObj($oMyError) Then
        $HexNumber = Hex($oMyError.number, 8)
        ConsoleWrite($oMyError.scriptline & '  $HexNumber = ' & $HexNumber & "Windescription is: " & $oMyError.description & "|" & $oMyError.windescription  & @lf) ;### Debug Console
        SetError($HexNumber)
    Else
        SetError(1)
    EndIf
    Return 0
EndFunc   ;==>ComError

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
star2

thanks boss


[quote]Baby you're all that I want, When you're lyin' here in my armsI'm findin' it hard to believe, We're in heavenAnd love is all that I need , And I found it there in your heartIt isn't too hard to see, We're in heaven .Bryan Adams[/quote].............................................................................[u]AUTOIT[/u]

Share this post


Link to post
Share on other sites
PcExpert

Thanks JdeB!

Works Fine now

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  

×