Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Adding User account to the local PC

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,28920
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Adding User account to the local PC
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Adding User account to the local PC - 12/12/2005 8:47:02 AM   
  gotoman

 

Posts: 22
Score: 0
Joined: 12/5/2005
Status: offline
Hi
I am trying to add a domain user to the user accounts on the local PC.
Has any one tryed this.
Ben
 
 
Post #: 1
 
 RE: Adding User account to the local PC - 12/13/2005 12:23:21 AM   
  Country73


Posts: 733
Score: 10
Joined: 8/25/2004
From: USA
Status: offline
Is this what you are looking for:


      

Copied straight from Here.

(in reply to gotoman)
 
 
Post #: 2
 
 RE: Adding User account to the local PC - 12/13/2005 12:50:45 AM   
  ginolard


Posts: 1068
Score: 21
Joined: 8/10/2005
Status: offline
Actually, the above code will only add a LOCAL user to a local group.  To add a domain user you need this code.

strComputer="xxxxxx"
strGroup="xxxxx"
strDomain="xxxxx"
strUser="xxxx"
Set objGroupToUpdate = GetObject("WinNT://" & strComputer & "/" & strGroup & ",group")
Set objUserToAdd = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
objGroup.Add(objUserToAdd.ADsPath)

(in reply to Country73)
 
 
Post #: 3
 
 RE: Adding User account to the local PC - 12/13/2005 2:43:38 AM   
  Country73


Posts: 733
Score: 10
Joined: 8/25/2004
From: USA
Status: offline
Doh!
Got me on that one, I posted my response without double checking the original question.

Nice catch ginolard

(in reply to ginolard)
 
 
Post #: 4
 
 RE: Adding User account to the local PC - 12/13/2005 6:19:44 AM   
  gotoman

 

Posts: 22
Score: 0
Joined: 12/5/2005
Status: offline
I have the below code.
I am i doing somthing wrong i get a run time error
<------
strComputer="IS20"
strGroup="Administrators"
strDomain="MPDC"
strUser="Bhill"
Set objGroupToUpdate = GetObject("WinNT://" & strComputer & "/" & strGroup & ",group")
Set objUserToAdd = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
objGroup.Add(objUserToAdd.ADsPath)
--------->
I get

Error:      Ogject required: 'objGroup'
Code:      800A01A8

(in reply to Country73)
 
 
Post #: 5
 
 RE: Adding User account to the local PC - 12/13/2005 6:44:26 AM   
  Country73


Posts: 733
Score: 10
Joined: 8/25/2004
From: USA
Status: offline
Change that last line from:

objGroup.Add(objUserToAdd.ADsPath)

To:

objGroupToUpdate.Add(objUserToAdd.ADsPath)

(in reply to gotoman)
 
 
Post #: 6
 
 RE: Adding User account to the local PC - 12/13/2005 9:57:01 AM   
  gotoman

 

Posts: 22
Score: 0
Joined: 12/5/2005
Status: offline
If i wanted just to update the  user that all ready exists.


Can i change  the last line to

objGroupToUpdate.Update(objUserToAdd.ADsPath)

(in reply to Country73)
 
 
Post #: 7
 
 RE: Adding User account to the local PC - 12/13/2005 7:43:36 PM   
  ginolard


Posts: 1068
Score: 21
Joined: 8/10/2005
Status: offline
No you can't.   objGroupToUpdate is simply the name of the object.

What exactly do you mean by "updating the user" anyway?

(in reply to gotoman)
 
 
Post #: 8
 
 RE: Adding User account to the local PC - 12/14/2005 6:11:29 AM   
  gotoman

 

Posts: 22
Score: 0
Joined: 12/5/2005
Status: offline
Just that all users are as local administrators on there pc's.
Only because Kix login script needed them to be.
Now the login script is in vbsi would like to change them to be power users.
Ben

(in reply to ginolard)
 
 
Post #: 9
 
 RE: Adding User account to the local PC - 12/15/2005 2:22:16 AM   
  ginolard


Posts: 1068
Score: 21
Joined: 8/10/2005
Status: offline
Then you have to delete them from the Adminstrator group and add them to the Power Users group

(in reply to gotoman)
 
 
Post #: 10
 
 RE: Adding User account to the local PC - 12/15/2005 8:52:55 AM   
  gotoman

 

Posts: 22
Score: 0
Joined: 12/5/2005
Status: offline
Cool Got it
Code Below.
<--------

On Error Resume Next
' *********** start User Name ****************
Set objNetwork = WScript.CreateObject("WScript.Network")
strUserName = objNetwork.UserName
computername= objNetwork.Computername
'************* End User Name *************

'*********** Start Removing User from Adminstrator group *******************
' group name to remove <span class="high">user</span> from
Set oGroupAdm = GetObject("WinNT://" & computername & "/Administrators")
' loop through all members of the Administrators group
For Each oAdmGrpUser In oGroupAdm.Members
' get the name and make it lowercase
sAdmGrpUser = LCase(oAdmGrpUser.Name)

If (sAdmGrpUser <> "administrator") And (sAdmGrpUser <> "domain admins") And (sAdmGrpUser = strUserName) Then
 oGroupAdm.Remove oAdmGrpUser.ADsPath
End if
Next
'*********** End Removing User from Adminstrator group *******************

'*********** Start Adding User from Power User group *******************
strComputer=computername
strGroup="Power Users"
strDomain="MPDC"
strUser=strUserName
Set objGroupToUpdate = GetObject("WinNT://" & strComputer & "/" & strGroup & ",group")
Set objUserToAdd = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")

objGroupToUpdate.Add(objUserToAdd.ADsPath)
'*********** End Adding User from Power User group *******************

---------->

(in reply to ginolard)
 
 
Post #: 11
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Adding User account to the local PC Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts