Sign in to follow this  
Followers 0
engine

Local account UDF

18 posts in this topic




#2 ·  Posted (edited)

I've been looking for this for some time now.

Nice job :P

Edit: 1 thousand posts :)

Edited by monoceres

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Nice job :):P:P

Share this post


Link to post
Share on other sites

Following the tip from this post -> http://www.autoitscript.com/forum/index.ph...st&p=540659

I updated the file. My intention is to have this UDF working for Windows 2000 too. However I am currently unable to test it under other than Windows XP.

Regards.


My contributions:Local account UDF Registry UDFs DriverSigning UDF Windows Services UDF [url="http://www.autoitscript.com/forum/index.php?showtopic=81880"][/url]

Share this post


Link to post
Share on other sites

This is great. I'll be using this on Windows Server 2003 so I'll let you know how it works there.

Share this post


Link to post
Share on other sites

Using this mostly in a Windows XP SP2 environment. Works like a charm. Had no problems creating, deleting or renaming local accounts. I build new systems for end users and this has been extremely reliable in helping to automate that process. Thank you for the excellent UDF.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Update: Works fine in Windows Server 2k3. I'm specifically using the _AccountEnableProperty function to enable the Password never expires checkbox.

Also, I would like to credit you in my being able to come up with a similar solution for IIS Management. I needed to check the Write flag in the Virtual Directory properties dialogue. I used your UDF as a starting point on how to translate Microsofts sample scripts for IIS into AutoIt. I would also like to credit smashly for linking me to this topic as well as the Microsoft script repository. I've been working on that little check box for months. I'm so happy it's over! Thank you for the help.

I'll attach the UDF here for your amusement. Keep in mind, I only implemented the functionality for that one check box, although the way I structured it, additional Cases could be added for the other properties. I also didn't go all out like you did and translate the entire IIS section. Just the one regarding Virtual Directory's properties.

IIsFtp.au3

Edited by Colin

Share this post


Link to post
Share on other sites

Hi, I am trying to run

_AccountAddToGroup

on PE windows but it does not work. What dependency does this script have?

Share this post


Link to post
Share on other sites

Hi Engine,

I am using Windows 7 32 bit machine and i am trying to use the function _GroupEnumMembers. The script runs successfully but i am not getting any result even if i wait for more than 4 minutes. But the same time the function _GroupEnum works fine. Please let me know where i am making a mistake.

#include"LocalAccount.au3"
#include"Array.au3"
$result = _GroupEnumMembers("Administrators")
_ArrayDisplay($result)

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
Share on other sites

Hi Engine,

I am using Windows 7 32 bit machine and i am trying to use the function _GroupEnumMembers. The script runs successfully but i am not getting any result even if i wait for more than 4 minutes. But the same time the function _GroupEnum works fine. Please let me know where i am making a mistake.

#include"LocalAccount.au3"
#include"Array.au3"
$result = _GroupEnumMembers("Administrators")
_ArrayDisplay($result)

That script runs fine and fast on my machine.

try running this script

#include "LocalAccount.au3"
#include <Array.au3>
$result = _GroupEnumMembers("Administrators")
MsgBox(0, "Error", @error)
_ArrayDisplay($result)

If you see error different from 0, you probably aren't going to get any result on that _ArrayDisplay, like for never.


My contributions:Local account UDF Registry UDFs DriverSigning UDF Windows Services UDF [url="http://www.autoitscript.com/forum/index.php?showtopic=81880"][/url]

Share this post


Link to post
Share on other sites

That script runs fine and fast on my machine.

try running this script

#include "LocalAccount.au3"
#include <Array.au3>
$result = _GroupEnumMembers("Administrators")
MsgBox(0, "Error", @error)
_ArrayDisplay($result)

If you see error different from 0, you probably aren't going to get any result on that _ArrayDisplay, like for never.

i am getting an error message -2. :oops:

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

a small addition of mine: _GroupGetNameBySID()

useful, for example, if you want to add an account to the local administrators group, but its name is not "Administrators", because your installation of Windows is in a non-English language.

code adapted from here: 

http://blogs.technet.com/b/heyscriptingguy/archive/2005/11/02/how-can-i-determine-the-name-of-the-local-administrators-group.aspx

here's an example script with the function included:

Global Const $sLocalAdminGroup_SID = 'S-1-5-32-544'
Global Const $sLocalAdminGroup_Name = _GroupGetNameBySID($sLocalAdminGroup_SID)
If @error Then
    MsgBox(16, 'Error!', 'Cannot resolve the name of the local administrators group.')
Else
    MsgBox(64, 'Success!', 'The name of the local administrators group is:' & @CR & $sLocalAdminGroup_Name)
EndIf

Func _GroupGetNameBySID($sSID, $sComputer = @ComputerName)
    Local $objSystem = ObjGet("winmgmts:{ImpersonationLevel=impersonate}!\\" & $sComputer & "\root\cimv2")
    Local $objGroupList = $objSystem.ExecQuery('Select * from Win32_Group Where Domain="' & $sComputer & '" And SID="' & $sSID & '"')
    For $objGroup In $objGroupList ; should be only a single result, anyway returns the first result found
        Return $objGroup.Name
    Next
    Return SetError(1, 0, '')
EndFunc   ;==>_GroupGetNameBySID

note: not tested on remote computer.

and, as said before - REALLY GREAT UDF!  :thumbsup:

(3 years and not a single update is required!)

Edited by orbs

Share this post


Link to post
Share on other sites

another small contribution: _AccountShowInLogonScreen() lets you hide/unhide a user account from the Windows logon screen.

Func _AccountShowInLogonScreen($sUserName, $bShow, $sComputer = @ComputerName)
    Local $sHKLM = 'HKLM'
    Switch @OSArch
        Case 'X86'
            $sHKLM = 'HKLM'
        Case 'X64'
            $sHKLM = 'HKLM64'
        Case Else
            Return SetError(1, 0, 0)
    EndSwitch
    If $sComputer <> @ComputerName Then $sHKLM = '\\' & $sComputer & '\' & $sHKLM
    If $bShow Then
        RegDelete($sHKLM & '\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList', $sUserName)
    Else
        RegWrite($sHKLM & '\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList', $sUserName, 'REG_DWORD', 0)
    EndIf
    If @error Then Return SetError(1, 0, 0)
    Return 1
EndFunc   ;==>_AccountShowInLogonScreen

note: not tested on remote computer.

Share this post


Link to post
Share on other sites

I noticed that there were functions to set account and group information, but there were no functions to get this information.  Here are two additional functions to resolve this issue.  

#include "LocalAccount.au3"
#include <Array.au3>


Global $aInfo = _AccountGetInfo("Administrator")
;~ Global $aInfo = _AccountGetInfo("Guest")
_ArrayDisplay($aInfo)

Global $sInfo = _GroupGetInfo("Administrators")
;~ Global $sInfo = _GroupGetInfo("Power Users")
;~ Global $sInfo = _GroupGetInfo("Remote Desktop Users")
;~ Global $sInfo = _GroupGetInfo("Users")
MsgBox(0, "Test", $sInfo)



; #FUNCTION# ====================================================================================================================
;
; Name...........:  _AccountGetInfo
; Description ...:  Gets information related to a local user account.
; Syntax.........:  _AccountGetInfo($sUserName [, $sComputer])
;                   $sUserName - Local user account name
; Parameters ....:  $sComputer - [Optional] Computer name
;                               The local computer is default
; Return values .:  Success - Returns 1D array
;                   Array[0] = Full Name
;                   Array[1] = Description
;                   Failure - Returns 0 and sets @error to -1
; Author ........:  AdamUL (Adam Lawrence)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......;
;
; ===============================================================================================================================

Func _AccountGetInfo($sUserName, $sComputer = @ComputerName)
    Local $objIADsError = ObjEvent("AutoIt.Error", "objIADsErrFunc")
    #forceref $objIADsError
    Local $objUser = ObjGet("WinNT://" & $sComputer & "/" & $sUserName & ", user")
    If @error Then Return SetError(1, 0, 0)
    Local $aReturn[2]
    With $objUser
        $aReturn[0] = .FullName
        $aReturn[1] = .Description
    EndWith
    If @error Then Return SetError($IADsError, 0, $IADsError + 1)

    Return $aReturn
EndFunc ;==> _AccountGetInfo

; #FUNCTION# ====================================================================================================================
;
; Name...........:  _GroupGetInfo
; Description ...:  Gets information related to a local group.
; Syntax.........:  _GroupGetInfo($sGroup [ ,$sComputer])
;                   $sGroup - Local user group name
; Parameters ....:  $sComputer - [Optional] Computer name
;                               The local computer is default
; Return values .:  Success - Returns a string sescription of the local group
;                   Failure - Returns 0 and sets @error to -1
; Author ........:  AdamUL (Adam Lawrence)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......;
;
; ===============================================================================================================================

Func _GroupGetInfo($sGroup, $sComputer = @ComputerName)
    Local $objIADsError = ObjEvent("AutoIt.Error", "objIADsErrFunc")
    #forceref $objIADsError
    Local $objGroup = ObjGet("WinNT://" & $sComputer & "/" & $sGroup & ", group")
    If @error Then Return SetError(1, 0, 0)
    Local $sReturn = $objGroup.Description
    If @error Then Return SetError($IADsError, 0, $IADsError + 1)
    
    Return $sReturn
EndFunc ;==> _GroupGetInfo

 

Adam

 

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