NTDOCAdministrator
(KiX Master)
2006-03-13 09:14 AM
Request for Comment - LocalUserGroupManage()

Please provide constructive feedback for a possible new UDF, not just some dribble to increase your post count.

Thanks

Dim $New
$New = LocalUserGroupManage(@WKSTA,'create','user',,,'Barney','12345')
If @ERROR
'There was an error managing the account. ' + @ERROR + ' - ' + @SERROR ?
Else
'Account management was successful. ' + @ERROR + ' - ' + @SERROR ?
EndIf
$New = LocalUserGroupManage(@WKSTA,'add','user',@WKSTA,'Administrators','Barney')
If @ERROR
'There was an error managing the account. ' + @ERROR + ' - ' + @SERROR ?
Else
'Account management was successful. ' + @ERROR + ' - ' + @SERROR ?
EndIf

;Parameters:
; $sComputer = Name of the computer you want to manage
; $Action = One of two choices only CREATE / ADD
; $Type = One of two choices GROUP / USER
; $Domain can be either a Network Computer or the Local Computer
; Normally one would only assign Domain to the Local Computer for adding a pre-existing local account to a local group
; $GName is the GROUP name you want to Add to or Create
; $UName is the USER name you want to Add or Create
; $Pass is the password to assign to a new account you are creating

Function LocalUserGroupManage($sComputer,$Action,$Type,Optional $Domain,$GName,$UName,$Pass)
Dim $Account,$User,$Group,$Set
If $Action = 'create'
$Account = GetObject('WinNT://' + $sComputer + "")
If Not @ERROR
If $Type = 'group'
$User = $Account.Create($Type,$GName)
$LocalUserGroupManage = Val('&' + Right(DecToHex(@ERROR), 4))
Else
$User = $Account.Create($Type,$UName)
$LocalUserGroupManage = Val('&' + Right(DecToHex(@ERROR), 4))
EndIf
If $Pass
$Set = $User.SetPassword($Pass)
EndIf
$Set = $User.SetInfo
EndIf
EndIf
If $Action = 'add'
$Group = GetObject('WinNT://' + $sComputer + '/'+$GName+',group')
$User = GetObject('WinNT://' + $Domain + '/'+$UName+',user')
If Not @ERROR
$Group.Add($User.ADsPath)
$LocalUserGroupManage = Val('&' + Right(DecToHex(@ERROR), 4))
EndIf
EndIf
Exit Val('&' + Right(DecToHex(@ERROR), 4))
EndFunction



Radimus
(KiX Supporter)
2006-03-13 11:54 AM
Re: Request for Comment - LocalUserGroupManage()

I'd use case $action = 'Add', but that is just a personal preference.

I'd make this 2 UDFs
Function ManageLocalGroup($computer, $LocalGroup, $ArrayOfNames, optional InsertOrReplace)

Function CreateLocalUser($computer, $newUser, $NewPass, optional $LocalGroup)


I see normal use as:
1) I need to create a local account and put in a specific local group
2) I need to update a local group on every PC to have (only) specific accts

I'm a big believer in a UDF having only 1 function... although I can see the CreateLocalUser() to have an optional $delete parameter


NTDOCAdministrator
(KiX Master)
2006-03-13 06:35 PM
Re: Request for Comment - LocalUserGroupManage()

Thanks for the feedback Rad. I get what you mean and I was already sort of thinking that because in reality the "create" user actually needs to have/allow a few more parameters not including groups which would make the parameters way too encumbering compared to most UDF scripts.
 
I'll review making it into a couple UDFs as suggested over the week as I get time.

(post 7766)