Solved

Have a file with Machine name and Ntlogin. Need to add the users in the local Administrator group of the machine.

Posted on 2008-10-23
61
236 Views
Last Modified: 2012-06-27
Hi,

Have a file with Machine name and Ntlogin. Need to add the users in the local Administrator group of the machine.
For each machine with the user next to him.

File as this

Machine name,Username/NT Login

Is there a way to run a script and get this done remotely.

Regards
Sharath
0
Comment
Question by:bsharath
  • 37
  • 24
61 Comments
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
This should do it...
SourceFile = "C:\SourceFile.txt"

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
 

arrData = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)
 

For each item in arrData

  arrValue = Split(item,",")

  PC=arrValue(0)

  User=arrValue(1)

  AddUserToAdmin (User, PC)

Next
 

wscript.quit
 

Sub AddUserToAdmin (strUser, strPC)

  Dim objUser : Set objUser = GetObject("WinNT://" & strPC & "/" strUser)

  Dim objAdmin : Set objAdmin = GetObject("WinNT://" & strPC & "/Administrators")

  objAdmin.Add (objUser.ADsPath)

  Set objAdmin = Nothing

  Set objUser = Nothing

End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      10
Char:      28
Error:      Cannot use parentheses when calling a Sub
Code:      800A0414
Source:       Microsoft VBScript compilation error

---------------------------
OK  
---------------------------
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      10
Char:      28
Error:      Cannot use parentheses when calling a Sub
Code:      800A0414
Source:       Microsoft VBScript compilation error

---------------------------
OK  
---------------------------
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Change line 10 from this:
  AddUserToAdmin (User, PC)
to this:
  AddUserToAdmin User, PC
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      16
Char:      66
Error:      Expected ')'
Code:      800A03EE
Source:       Microsoft VBScript compilation error

---------------------------
OK  
---------------------------
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      16
Char:      66
Error:      Expected ')'
Code:      800A03EE
Source:       Microsoft VBScript compilation error

---------------------------
OK  
---------------------------
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
What does the message reveal in this version?
SourceFile = "C:\SourceFile.txt"

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")

 

arrData = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)

 

For each item in arrData

  arrValue = Split(item,",")

  PC=Trim(arrValue(0))

  User=Trim(arrValue(1))

  AddUserToAdmin User, PC

Next

 

wscript.quit

 

Sub AddUserToAdmin (strUser, strPC)

  wscript.echo "Adding " & strUser & " to Administrators group on " & strPC

  Dim objUser : Set objUser = GetObject("WinNT://" & strPC & "/" strUser)

  Dim objAdmin : Set objAdmin = GetObject("WinNT://" & strPC & "/Administrators")

  objAdmin.Add (objUser.ADsPath)

  Set objAdmin = Nothing

  Set objUser = Nothing

End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
I getb this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      17
Char:      66
Error:      Expected ')'
Code:      800A03EE
Source:       Microsoft VBScript compilation error

---------------------------
OK  
---------------------------
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
I getb this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      17
Char:      66
Error:      Expected ')'
Code:      800A03EE
Source:       Microsoft VBScript compilation error

---------------------------
OK  
---------------------------
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Odd...not sure what ')' it's expecting.
If this version doesn't work - comment out that line (should be line 18 now...starts with Dim objUser...by placing a ' at the start of it)
SourceFile = "C:\SourceFile.txt"

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")

 

arrData = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)

 

For each item in arrData

  arrValue = Split(item,",")

  PC=Trim(arrValue(0))

  User=Trim(arrValue(1))

  AddUserToAdmin User, PC

Next

 

wscript.quit

 

Sub AddUserToAdmin (strUser, strPC)

  wscript.echo "Adding " & strUser & " to Administrators group on " & strPC

  UserPath=strPC & "/" & strUser

  Dim objUser : Set objUser = GetObject("WinNT://" & UserPath)

  Dim objAdmin : Set objAdmin = GetObject("WinNT://" & strPC & "/Administrators")

  objAdmin.Add (objUser.ADsPath)

  Set objAdmin = Nothing

  Set objUser = Nothing

End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
Now i get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      9
Char:      3
Error:      Subscript out of range: '[number: 1]'
Code:      800A0009
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Looks to be the input file...
Presumably it's laid out like
ComputerName,UserName
correct?
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
Sorry have a ; instead of a ,

Now i get this

---------------------------
Windows Script Host
---------------------------
Adding Echj to Administrators group on Dev-mrd01
---------------------------
OK  
---------------------------


Then this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      18
Char:      17
Error:      The group name could not be found.
Code:      800708AC
Source:       (null)

---------------------------
OK  
---------------------------

0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
Sorry have a ; instead of a ,

Now i get this

---------------------------
Windows Script Host
---------------------------
Adding Echj to Administrators group on Dev-mrd01
---------------------------
OK  
---------------------------


Then this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      18
Char:      17
Error:      The group name could not be found.
Code:      800708AC
Source:       (null)

---------------------------
OK  
---------------------------

0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
I think the user/pc are off...I was using user,pc - but it looks like you said it was pc,user?Sorry - it's late here...if this still fails to work, check that the Administrators group exists as that name on the target device.
SourceFile = "C:\SourceFile.txt"

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")

 

arrData = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)

 

For each item in arrData

  arrValue = Split(item,",")

  PC=Trim(arrValue(0))

  User=Trim(arrValue(1))

  AddUserToAdmin PC, User

Next

 

wscript.quit

 

Sub AddUserToAdmin (strPC, strUser)

  UserPath=strPC & "/" & strUser

  Dim objUser : Set objUser = GetObject("WinNT://" & UserPath)

  Dim objAdmin : Set objAdmin = GetObject("WinNT://" & strPC & "/Administrators")

  objAdmin.Add (objUser.ADsPath)

  Set objAdmin = Nothing

  Set objUser = Nothing

End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      17
Char:      17
Error:      Unspecified error
Code:      80004005
Source:       (null)

---------------------------
OK  
---------------------------

Should i use it as
USer,pC?
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      17
Char:      17
Error:      Unspecified error
Code:      80004005
Source:       (null)

---------------------------
OK  
---------------------------

Should i use it as
USer,pC?
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
No I corrected it in the code - should be
pc,user

To reduce the space, I'll just update the subroutine...try replacing the entire sub at the bottom with this one:
It should pop up a box that says

Dev-mrd01/Echj

Does that user already exist on the target machine?  Or are you trying to add a domain user?



Sub AddUserToAdmin (strPC, strUser)

  UserPath=strPC & "/" & strUser

msgbox UserPath

  Dim objUser : Set objUser = GetObject("WinNT://" & UserPath)

  Dim objAdmin : Set objAdmin = GetObject("WinNT://" & strPC & "/Administrators")

  objAdmin.Add (objUser.ADsPath)

  Set objAdmin = Nothing

  Set objUser = Nothing

End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
I get this

---------------------------

---------------------------
Echj/Dev-mrd01
---------------------------
OK  
---------------------------

But get this later

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      18
Char:      17
Error:      Unspecified error
Code:      80004005
Source:       (null)

---------------------------
OK  
---------------------------
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
I get this

---------------------------

---------------------------
Echj/Dev-mrd01
---------------------------
OK  
---------------------------

But get this later

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      18
Char:      17
Error:      Unspecified error
Code:      80004005
Source:       (null)

---------------------------
OK  
---------------------------
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Hmm..something wrong with the add routine...another test:

Sub AddUserToAdmin (strPC, strUser)

  UserPath=strPC & "/" & strUser

  Dim objUser : Set objUser = GetObject("WinNT://" & UserPath)

msgbox objUser.Name & vbNewLine & objUser.ADsPath

  Dim objAdmin : Set objAdmin = GetObject("WinNT://" & strPC & "/Administrators")

msgbox objAdmin.Name

  objAdmin.Add (objUser.ADsPath)

  Set objAdmin = Nothing

  Set objUser = Nothing

End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
I get this
---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      17
Char:      17
Error:      Unspecified error
Code:      80004005
Source:       (null)

---------------------------
OK  
---------------------------
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
no popups at all?
Does this user account already exist on the target device?
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
No popup's just the error.
No the user is not a member of Administrators group...
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Right, but the user you're trying to add...is that user already defined on the target PC, or is this supposed to be a domain account?
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
The user i am trying to add is a Domain Account. I have running from an account with Domain Admin permissions on to a Remote machine name in the file with the Domain User name.

0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
The user i am trying to add is a Domain Account. I have running from an account with Domain Admin permissions on to a Remote machine name in the file with the Domain User name.

0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
That changes things...we're using the WinNT provider to do this, so we either have to switch to LDAP, or you might be able to get by with this change:

Note the change to the objUser path - you'll need to enter your actual domain name there...
Sub AddUserToAdmin (strPC, strUser)

  Dim objUser : Set objUser = GetObject("WinNT://YourDomain/" & strUser)

  Dim objAdmin : Set objAdmin = GetObject("WinNT://" & strPC & "/Administrators")

  objAdmin.Add (objUser.ADsPath)

  Set objAdmin = Nothing

  Set objUser = Nothing

End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      17
Char:      18
Error:      The network path was not found.
Code:      80070035
Source:       (null)

---------------------------
OK  
---------------------------
 
I have the txt file as

Machine name,Username/NT Login
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
What do you mean by Username/NT Login
Can you post a line or two from your file?
What's your domain name?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 11

Author Comment

by:bsharath
Comment Utility
Domain Name " Development"

I Have this in the file
Dev-mrd01,SharathK
Inside,Sharathk
Dev-mrd01,Echj
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
Domain Name " Development"

I Have this in the file
Dev-mrd01,SharathK
Inside,Sharathk
Dev-mrd01,Echj
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Full script...let me know...
SourceFile = "C:\SourceFile.txt"

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")

 

arrData = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)

 

For each item in arrData

  arrValue = Split(item,",")

  PC=Trim(arrValue(0))

  User=Trim(arrValue(1))

  AddUserToAdmin User, PC

Next

 

wscript.quit

 

Sub AddUserToAdmin (strPC, strUser)

  Dim objUser : Set objUser = GetObject("WinNT://Development/" & strUser)

  Dim objAdmin : Set objAdmin = GetObject("WinNT://" & strPC & "/Administrators")

  objAdmin.Add (objUser.ADsPath)

  Set objAdmin = Nothing

  Set objUser = Nothing

End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      17
Char:      18
Error:      The network path was not found.
Code:      80070035
Source:       (null)

---------------------------
OK  
---------------------------

I have 5 machine names with users and all machines and NTlogins are live...
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
So, you can successfully ping Dev-mrd01?
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
Yes i can
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Odd - try moving another line up top in your file, just for testing.  And you do have access to these PCs as an Admin, correct?

Other than that, try this version...doubt it'll yield much different though.
SourceFile = "C:\SourceFile.txt"

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")

 

arrData = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)

 

For each item in arrData

  arrValue = Split(item,",")

  PC=Trim(arrValue(0))

  User=Trim(arrValue(1))

  AddUserToAdmin User, PC

Next

 

wscript.quit

 

Sub AddUserToAdmin (strPC, strUser)

  Dim objUser : Set objUser = GetObject("WinNT://Development/" & strUser)

  Dim objPC : Set objPC = GetObject("WinNT://" & strPC)

  Dim objAdmin : Set objAdmin = GetObject(objPC.ADsPath & "/Administrators")  
 

  objAdmin.Add (objUser.ADsPath)

  Set objAdmin = Nothing

  Set objPC = Nothing

  Set objUser = Nothing

End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      18
Char:      18
Error:      The network path was not found.
Code:      80070035
Source:       (null)

---------------------------
OK  
---------------------------
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
That looks like it's having trouble finding the group Administrators...the line before seems to have gotten to the PC okay.
Can you verify the Admin group name is Administrators and exists on that device?
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
Yes The group name is Administrators and it exists...
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Tested this further on a couple of my work computers with no problem.

Line 17 appears to be working, so the computer is being discovered.  Perhaps the adspath is incorrect?

Change these lines - I dropped a new line in between them:


  Dim objPC : Set objPC = GetObject("WinNT://" & strPC)
Msgbox objPC.AdsPath & "/Administrators"
  Dim objAdmin : Set objAdmin = GetObject(objPC.ADsPath & "/Administrators")

I'd like to know what pop up message you get.
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
First got this
---------------------------

---------------------------
WinNT://Echj/Administrators
---------------------------
OK  
---------------------------

Then this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      19
Char:      18
Error:      The network path was not found.
Code:      80070035
Source:       (null)

---------------------------
OK  
---------------------------
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
First got this
---------------------------

---------------------------
WinNT://Echj/Administrators
---------------------------
OK  
---------------------------

Then this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      19
Char:      18
Error:      The network path was not found.
Code:      80070035
Source:       (null)

---------------------------
OK  
---------------------------
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
I've been unable to reproduce this - it works on my network with 5 different devices.
Can you try reordering your input list and see if it's just a problem with that one device?
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      19
Char:      18
Error:      The network path was not found.
Code:      80070035
Source:       (null)

---------------------------
OK  
---------------------------


Full code as in snippet

The txt file is as

Machinename,Username
SourceFile = "C:\SourceFile.txt"

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")

 

arrData = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)

 

For each item in arrData

  arrValue = Split(item,",")

  PC=Trim(arrValue(0))

  User=Trim(arrValue(1))

  AddUserToAdmin User, PC

Next

 

wscript.quit

 

Sub AddUserToAdmin (strPC, strUser)

  Dim objUser : Set objUser = GetObject("WinNT://Development/" & strUser)

  Dim objPC : Set objPC = GetObject("WinNT://" & strPC)

Msgbox objPC.AdsPath & "/Administrators"

  Dim objAdmin : Set objAdmin = GetObject(objPC.ADsPath & "/Administrators")  

 

  objAdmin.Add (objUser.ADsPath)

  Set objAdmin = Nothing

  Set objPC = Nothing

  Set objUser = Nothing

End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      19
Char:      18
Error:      The network path was not found.
Code:      80070035
Source:       (null)

---------------------------
OK  
---------------------------


Full code as in snippet

The txt file is as

Machinename,Username
SourceFile = "C:\SourceFile.txt"

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")

 

arrData = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)

 

For each item in arrData

  arrValue = Split(item,",")

  PC=Trim(arrValue(0))

  User=Trim(arrValue(1))

  AddUserToAdmin User, PC

Next

 

wscript.quit

 

Sub AddUserToAdmin (strPC, strUser)

  Dim objUser : Set objUser = GetObject("WinNT://Development/" & strUser)

  Dim objPC : Set objPC = GetObject("WinNT://" & strPC)

Msgbox objPC.AdsPath & "/Administrators"

  Dim objAdmin : Set objAdmin = GetObject(objPC.ADsPath & "/Administrators")  

 

  objAdmin.Add (objUser.ADsPath)

  Set objAdmin = Nothing

  Set objPC = Nothing

  Set objUser = Nothing

End Sub

Open in new window

0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Sorry Sharath, please try this one...
SourceFile = "C:\SourceFile.txt"

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")

 

arrData = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)

 

For each item in arrData

  arrValue = Split(item,",")

  PC=Trim(arrValue(0))

  User=Trim(arrValue(1))

  AddUserToAdmin PC, User

Next

 

wscript.quit

 

Sub AddUserToAdmin (strPC, strUser)

  On Error Resume Next

  Dim objUser : Set objUser = GetObject("WinNT://Development/" & strUser)

  Dim objPC : Set objPC = GetObject("WinNT://" & strPC)

  Dim objAdmin : Set objAdmin = GetObject(objPC.ADsPath & "/Administrators")  

 

  objAdmin.Add (objUser.ADsPath)

  If Err.Number <> 0 Then

    wscript.echo "An error has occured:" & vbNewLine & Err.Description

  End If

  Set objAdmin = Nothing

  Set objPC = Nothing

  Set objUser = Nothing

End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
Sorry for the delay...
I get this...

a box
An error has occured then this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      8
Char:      3
Error:      Subscript out of range: '[number: 0]'
Code:      800A0009
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
Sorry for the delay...
I get this...

a box
An error has occured then this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      8
Char:      3
Error:      Subscript out of range: '[number: 0]'
Code:      800A0009
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Apology unnecessary.
That would indicate that there is no PC in the first field...this should test for empty lines:
SourceFile = "C:\SourceFile.txt"

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")

 

arrData = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)

 

For each item in arrData

  If item <> "" Then

    arrValue = Split(item,",")

    PC=Trim(arrValue(0))

    User=Trim(arrValue(1))

    AddUserToAdmin PC, User

  End If

Next

 

wscript.quit

 

Sub AddUserToAdmin (strPC, strUser)

  On Error Resume Next

  Dim objUser : Set objUser = GetObject("WinNT://Development/" & strUser)

  Dim objPC : Set objPC = GetObject("WinNT://" & strPC)

  Dim objAdmin : Set objAdmin = GetObject(objPC.ADsPath & "/Administrators")  

 

  objAdmin.Add (objUser.ADsPath)

  If Err.Number <> 0 Then

    wscript.echo "An error has occured:" & vbNewLine & Err.Description

  End If

  Set objAdmin = Nothing

  Set objPC = Nothing

  Set objUser = Nothing

End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
I just get this

---------------------------
Windows Script Host
---------------------------
An error has occured:


---------------------------
OK  
---------------------------
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
I just get this

---------------------------
Windows Script Host
---------------------------
An error has occured:


---------------------------
OK  
---------------------------
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
If you click OK, do any of them get added?  That's a bypassable error...
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
You are right now it add's the use but get that error....

Can i get a done button or a success/failure results file.
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
You are right now it add's the use but get that error....

Can i get a done button or a success/failure results file.
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Run the script with

cscript "C:\Add Users to Groups in Machines.vbs"
SourceFile = "C:\SourceFile.txt"

OutputFile = "C:\AdminAddResults.txt"

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim objLog : Set objLog = objFSO.CreateTextFile(OutputFile)

 

arrData = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)

 

For each item in arrData

  If item <> "" Then

    arrValue = Split(item,",")

    PC=Trim(arrValue(0))

    User=Trim(arrValue(1))

    objLog.WriteLine "Attempting to add " & User & " to Admin group on " & PC

    AddUserToAdmin PC, User

  End If

Next
 

objLog.Close

wscript.quit

 

Sub AddUserToAdmin (strPC, strUser)

  On Error Resume Next

  Dim objUser : Set objUser = GetObject("WinNT://Development/" & strUser)

  Dim objPC : Set objPC = GetObject("WinNT://" & strPC)

  Dim objAdmin : Set objAdmin = GetObject(objPC.ADsPath & "/Administrators")  

 

  objAdmin.Add (objUser.ADsPath)

  If Err.Number <> 0 Then

    objLog.WriteLine vbTab "An error has occured:  " & Err.Description

  Else

    objLog.WriteLine vbTab & "...added successfully."

  End If

  Set objAdmin = Nothing

  Set objPC = Nothing

  Set objUser = Nothing

End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
I get this

C:\>cscript "C:\Add Users to Groups in Machines.vbs"
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\Add Users to Groups in Machines.vbs(29, 28) Microsoft VBScript compilation error: Expected end of statement
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
I get this

C:\>cscript "C:\Add Users to Groups in Machines.vbs"
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\Add Users to Groups in Machines.vbs(29, 28) Microsoft VBScript compilation error: Expected end of statement
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
Comment Utility
Sorry about that...
SourceFile = "C:\SourceFile.txt"

OutputFile = "C:\AdminAddResults.txt"

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim objLog : Set objLog = objFSO.CreateTextFile(OutputFile)

 

arrData = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)

 

For each item in arrData

  If item <> "" Then

    arrValue = Split(item,",")

    PC=Trim(arrValue(0))

    User=Trim(arrValue(1))

    objLog.WriteLine "Attempting to add " & User & " to Admin group on " & PC

    AddUserToAdmin PC, User

  End If

Next

 

objLog.Close

wscript.quit

 

Sub AddUserToAdmin (strPC, strUser)

  On Error Resume Next

  Dim objUser : Set objUser = GetObject("WinNT://Development/" & strUser)

  Dim objPC : Set objPC = GetObject("WinNT://" & strPC)

  Dim objAdmin : Set objAdmin = GetObject(objPC.ADsPath & "/Administrators")  

 

  objAdmin.Add (objUser.ADsPath)

  If Err.Number <> 0 Then

    objLog.WriteLine vbTab & "An error has occured:  " & Err.Description

  Else

    objLog.WriteLine vbTab & "...added successfully."

  End If

  Set objAdmin = Nothing

  Set objPC = Nothing

  Set objUser = Nothing

End Sub

Open in new window

0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Glad it's working for you - thanx for the grade! :^)
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
Thank U very much... Very useful one for me... :-))
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now