Page 1 of 1 1
Topic Options
#158894 - 2006-03-13 09:14 AM Request for Comment - LocalUserGroupManage()
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11616
Loc: CA
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


Top
#158895 - 2006-03-13 11:54 AM Re: Request for Comment - LocalUserGroupManage()
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
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
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#158896 - 2006-03-13 06:35 PM Re: Request for Comment - LocalUserGroupManage()
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11616
Loc: CA
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)


Edited by NTDOC (2006-03-13 06:36 PM)

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 319 anonymous users online.
Newest Members
Kelly001, MichaelK72, Janneman, standardbruker, maikoenig2001
17773 Registered Users

Generated in 0.029 seconds in which 0.011 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org