orange Posted February 12, 2007 Share Posted February 12, 2007 (edited) Here is a little function that I whipped up to create and ADMIN user with or without password. For whatever reason, _RunDOS() does not work to execute the "net user" command, so I have the function create a temporary *.cmd file, execute it, then return. Because of this, the return values of the console can't be read (or at least I don't know how) -- is there anyone who can make this run silently and better? This is extremely rudimentary, help on this would be great. *********UPDATED CODE****************** func _CreateAdmin($new_user = "NewUser", $password = '') $new_user = stringstripws($new_user,8) if IsAdmin() = 0 then SetError(1) return 0 EndIf $file_contents = '@echo off'& _ @crlf & 'net user '&$new_user&' '&$password&' /add' & _ @crlf & 'net localgroup administrators /add '&$new_user _filecreate(@tempdir & "\admincreate.cmd") $file_handle = fileopen(@tempdir & "\admincreate.cmd",2) filewriteline($file_handle,$file_contents) fileclose($file_handle) $exit_code= run (@tempdir & "\admincreate.cmd","",@SW_HIDE,2) filedelete(@tempdir & "\admincreate.cmd") if stringinstr(StdoutRead($exit_code),"sucessfully") then SetError(0) return 1 Else seterror(2) return 0 EndIf EndFunc Edited February 12, 2007 by orange Link to comment Share on other sites More sharing options...
rogdog Posted February 13, 2007 Share Posted February 13, 2007 (edited) CODE$Name = 'NewUser' $Password = 'MyPassword' $GroupName = 'Administrators' If Not FileExists(EnvGet('AllUsersProfile') & '\..\' & $name) Then RunWait(@ComSpec & ' /c ' & _ 'Net User ' & $name & ' ' & $password & ' /add &&' & _ 'Net LocalGroup ' & $groupname & ' ' & $name & ' /add &' & _ 'Net Accounts /MaxPwAge:UnLimited', '', @SW_HIDE) EndIf Does this help ? Edited February 14, 2007 by rogdog My Scripts[topic="73325"]_ReverseDNS()[/topic]Favourite scripts by other members[topic="81687"]SNMP udf[/topic][topic="70759"]Using SNMP - MIB protocol[/topic][topic="39050"]_SplitMon:Section off your monitor!, split your monitor into sections for easy management[/topic][topic="73425"]ZIP.au3 UDF in pure AutoIt[/topic][topic="10534"]WMI ScriptOMatic tool for AutoIt[/topic][topic="51103"]Resources UDF embed/use any data/files into/from AutoIt compiled EXE files[/topic] Link to comment Share on other sites More sharing options...
mikiutama Posted February 16, 2007 Share Posted February 16, 2007 this is my version that i made about 2 years ago using batch format... and now i have convert it to autoit format... expandcollapse popup#NoTrayIcon #Include <Constants.au3> #Include <Process.au3> Opt("TrayMenuMode",1) Dim $title = "Account Editor v1.1", $status If Not IsAdmin() Then MsgBox(48, $title, "Since you don't have Admin Privilages, not all options will work ...", 5) EndIf TraySetClick(16) $1 = TrayCreateItem($title) TrayCreateItem("") $2 = TrayCreateMenu("Create New Account") $2a = TrayCreateMenu("As User Group", $2) $2b = TrayCreateMenu("As Admin Group", $2) $2c = TrayCreateItem("With password", $2a) $2d = TrayCreateItem("Without password", $2a) $2e = TrayCreateItem("With password", $2b) $2f = TrayCreateItem("Without password", $2b) $3 = TrayCreateItem("Change Account's Password") $4 = TrayCreateItem("Delete Existing Accounts") TrayCreateItem("") $5 = TrayCreateItem("Exit Account Editor") TraySetState() TrayTip("","",0) TrayTip($title, "Right click to start ...", 1) While 1 $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $2c $name = InputBox($title, "Enter New User Account Name", "" ," M" ,160 , 100, @desktopwidth-200, @desktopheight-150) If @error = 1 Then $msg = 0 Else $pass = InputBox($title, "Enter new password", "" ,"*M" ,160 , 100, @desktopwidth-200, @desktopheight-150) If @error = 1 Then $msg = 0 Else $status = Run("cmd.exe /c net user "&$name&" "&$pass&" /add", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Run("cmd.exe /c net localgroup Users /add "&$name&" /comment: ""Restricted User by Account Editor v1.1""", "", @SW_HIDE) _RunDOS("RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters ,1 ,True") result() EndIf EndIf Case $msg = $2d $name = InputBox($title, "Enter New User Account Name", "" ," M" ,160 , 100, @desktopwidth-200, @desktopheight-150) If @error = 1 Then $msg = 0 Else $status = Run("cmd.exe /c net user "&$name&" /add /Passwordreq:no", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Run("cmd.exe /c net localgroup Users /add "&$name&" /comment: ""Restricted User by Account Editor v1.1""", "", @SW_HIDE) _RunDOS("RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters ,1 ,True") result() EndIf Case $msg = $2e $name = InputBox($title, "Enter New Admin Account Name", "" ," M" ,160 , 100, @desktopwidth-200, @desktopheight-150) If @error = 1 Then $msg = 0 Else $pass = InputBox($title, "Enter new password", "" ,"*M" ,160 , 100, @desktopwidth-200, @desktopheight-150) If @error = 1 Then $msg = 0 Else $status = Run("cmd.exe /c net user "&$name&" "&$pass&" /add", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Run("cmd.exe /c net localgroup Administrators /add "&$name&" /comment: ""Admin Rights User by Account Editor v1.1""", "", @SW_HIDE) Run("cmd.exe /c net localgroup Users /del "&$name, "", @SW_HIDE) _RunDOS("RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters ,1 ,True") result() EndIf EndIf Case $msg = $2f $name = InputBox($title, "Enter New Admin Account Name", "" ," M" ,160 , 100, @desktopwidth-200, @desktopheight-150) If @error = 1 Then $msg = 0 Else $status = Run("cmd.exe /c net user "&$name&" /add /Passwordreq:no", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Run("cmd.exe /c net localgroup Administrators /add "&$name&" /comment: ""Admin Rights User by Account Editor v1.1""", "", @SW_HIDE) Run("cmd.exe /c net localgroup Users /del "&$name, "", @SW_HIDE) _RunDOS("RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters ,1 ,True") result() EndIf Case $msg = $3 $name = InputBox($title, "Enter Existing Account Name", "" ," M" ,160 , 100, @desktopwidth-200, @desktopheight-150) If @error = 1 Then $msg = 0 Else $pass = InputBox($title, "Enter New Password", "" ,"*M" ,160 , 100, @desktopwidth-200, @desktopheight-150) $status = Run("cmd.exe /c net user "&$name&" "&$pass, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) _RunDOS("RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters ,1 ,True") result() EndIf Case $msg = $4 $name = InputBox($title, "Enter Account Name To Delete", "" ," M" ,160 , 100, @desktopwidth-200, @desktopheight-150) If @error = 1 Then $msg = 0 Else $ask = MsgBox(49,$title, "Are You Sure?") If $ask <> 2 Then $status = Run("cmd.exe /c net user "&$name&" /delete", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) _RunDOS("RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters ,1 ,True") result() Else $msg = 0 EndIf EndIf Case $msg = $5 ExitLoop EndSelect WEnd Func result() While 1 $line = StdoutRead($status) If Not @error Then MsgBox(64, $title, $line) Else ExitLoop EndIf Wend While 1 $line = StderrRead($status) If Not @error Then MsgBox(0, $title, $line) Else ExitLoop EndIf Wend EndFunc Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now