Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


RemoveLocalAdmin - Excel Log

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> RemoveLocalAdmin - Excel Log
  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 >>
 RemoveLocalAdmin - Excel Log - 5/16/2006 4:16:06 AM   
  Country73


Posts: 712
Score: 8
Joined: 8/25/2004
From: USA
Status: offline
I started messing around with creating scripts that output their information directly to an Excel file.
This mainly came about due to an audit and the auditors wanting to see each step we went through on verifying local admin accounts across our network.
Here are three scripts to show the steps we had to go through.
The first script "List_LocalAdmins.vbs" only requires a text file called "pclist.txt" which contains a list of every machine you want to run the script against. (Each machine must be on it's own line, no blank lines between the machine lines)
Machine
Machine
etc...

      

The results from the first script, for us, were handed to upper management to look over. They would delete the rows of the machines that wanted to keep the local admin on (or just remove specific accounts they wanted to keep on that machine). Anything left in the spreadsheet would be removed.

This second script would read through the Excel file that the "List_LocalAdmins.vbs" has created. This will throw all the contents into a text file for the "RemoveAdminAccounts.vbs"

"CreateAdminRemoveList.vbs"

      

Now our "AdminAccounts.txt" is ready to run our "RemoveAdminAccounts.vbs"
For each machine, and account listed for the machine in the "AdminAccounts.txt" will be removed.
This script requires the CUSRMGR.EXE tool

"RemoveAdminAccount.vbs"

      

I do realize that this could have been completed in two (maybe even one) script; but I had to lay it out this way to walk our Auditors through it.
 
 
Post #: 1
 
 RE: RemoveLocalAdmin - Excel Log - 5/19/2006 6:22:32 AM   
  Country73


Posts: 712
Score: 8
Joined: 8/25/2004
From: USA
Status: offline
One last script to add; this one can actually take the place of "List_LocalAdmins.vbs" that I have posted as the first script.
This one will allow you to omit specific accounts (Admin, Administrator, etc...) that you know are setup as local admin.

Make sure you replace corp, that I have listed on line 107 of this script, with your domain.
The exact line is:
   oShell.Run oCMGR & "-u ""corp\" & fSplit(i) & """ -m " & strComputer & " -dlg ""Administrators""",0,True


      

Edit Reason:
Missed out a NEXT; dang nested statements...
Also made note of swapping your domain for what I have listed as corp, since I used this as a filler for my domain.

< Message edited by Country73 -- 7/19/2006 7:35:49 AM >

(in reply to Country73)
 
 
Revisions: 2 | Post #: 2
 
 RE: RemoveLocalAdmin - Excel Log - 7/17/2006 5:42:05 AM   
  Zenchee1

 

Posts: 4
Score: 0
Joined: 7/17/2006
Status: offline
Wonderful scripting, I am new to VBS, I know enough to be dangerous.  I was looking for just such a thing, I hate manually pulling people from the local admin groups.  I am having a problem with the actuall removemoveadmin.vbs script.  I keep getting

Expected statement 800A0400
Line 113
Char 1

It is the first End Function statement.  I can't seem to get it to work.  I have my co worker look at since he does VB and he can not figure out what is wrong either.  Any help would be greatly appriciated.
-Steve

_____________________________

Success through Design

(in reply to Country73)
 
 
Post #: 3
 
 RE: RemoveLocalAdmin - Excel Log - 7/18/2006 2:52:19 AM   
  Country73


Posts: 712
Score: 8
Joined: 8/25/2004
From: USA
Status: offline
Sorry, wasn't around any computers yesterday.

Are you actually receiving the error on this line:
     strInfo = strInfo & "," & objUser.Name & " \ " & objUser.Fullname


Are you receiving the error on a specific machine you run this against, or any machine you attempt to run it against?

(in reply to Zenchee1)
 
 
Post #: 4
 
 RE: RemoveLocalAdmin - Excel Log - 7/19/2006 2:37:07 AM   
  Zenchee1

 

Posts: 4
Score: 0
Joined: 7/17/2006
Status: offline
No worries on the timing.  I tried running the RemoveAdminAccount.vbs and I get

Line:  113
Char:  1

Error Expected Statement
Code 800A0400

I get this on every machine I try.  I honestly don't know enough to be able to tropuble shoot it, I enlisted a VB programmer at my place of employment and he seems to be at a loss also.  The other scripts you wrote work great, I just seem to be stuck.

I am runninf this on an XP SP2 machine with all current MS updates installed, don't know if you need to know that or not.

_____________________________

Success through Design

(in reply to Country73)
 
 
Post #: 5
 
 RE: RemoveLocalAdmin - Excel Log - 7/19/2006 5:08:00 AM   
  Country73


Posts: 712
Score: 8
Joined: 8/25/2004
From: USA
Status: offline
Depending on what program you are using to write your scripts in (PrimalScript, notepad, etc...), and what all you have actually modified on the script to fit your needs, it makes it a little difficult to determine what Line: 113 is and what would be causing the error.

According to my editor (TextPad), Line 113 = call verifyAccount(strComputer)

(By the way, my last response was on the wrong script, sorry about that)

If you can copy the line of code you are getting the error message on, then I'll see what I can figure out for you.
If you have made multiple modifications to the script, then I may need to see the whole thing to figure out what is going on.
Let's first start with you posting the exact line the script is erroring on.

(in reply to Zenchee1)
 
 
Post #: 6
 
 RE: RemoveLocalAdmin - Excel Log - 7/19/2006 6:25:03 AM   
  Zenchee1

 

Posts: 4
Score: 0
Joined: 7/17/2006
Status: offline
Sorry for the Lack of information in my posts, I am new to this type of forum.  I am using Ultra Edit for editing the script.  I did not modify anything in this script, I simply tried it out of the box.  Here is the part of the code I am getting the error with

FUNCTION stripMachine(myLine,strCount)
fSplit = Split(myLine,";")
strComputer = fSplit(0)
wscript.echo strCount & vbTab & strComputer
strCount = strCount - 1
Set cPingResults = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2").ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" + strComputer + "'")
   For Each oPingResult In cPingResults
       If oPingResult.StatusCode <> 0 Then
  call LogEvent(strComputer)
  Exit Function
End If
For i = 1 to UBound(fSplit)
  Set colGroups = GetObject("WinNT://" & strComputer & "")
   colGroups.Filter = Array("group")
   For Each oGroup In colGroups
    If (oGroup.Name = "Administrators") Then
     For Each oUser in oGroup.Members
      If LCase(oUser.Name) = LCase(fSplit(i)) Then
       oShell.Run oCMGR & "-u ""corp\" & fSplit(i) & """ -m " & strComputer & " -dlg ""Administrators""",0,True
      End If
     Next
    End If
   Next
Next
call verifyAccount(strComputer)
End Function   This line is where I am getting the error.    I don't see anything that would cause and error.  Once you alter this line to prevent the error, the error moves to each line after this one with the word "Function".

_____________________________

Success through Design

(in reply to Country73)
 
 
Post #: 7
 
 RE: RemoveLocalAdmin - Excel Log - 7/19/2006 7:30:04 AM   
  Country73


Posts: 712
Score: 8
Joined: 8/25/2004
From: USA
Status: offline
I'll have to double check on the script that I posted, but it looks like I might have missed a NEXT in there; also make sure you enter in your domain where I have corp listed. (I used that as a filler for the domain and should have mentioned that in my initial post of the script; I'll edit that when I go back over my initial post of the script)

FUNCTION stripMachine(myLine,strCount)
   fSplit = Split(myLine,";")
   strComputer = fSplit(0)
   wscript.echo strCount & vbTab & strComputer
   strCount = strCount - 1
   Set cPingResults = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2").ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" + strComputer + "'")
       For Each oPingResult In cPingResults
           If oPingResult.StatusCode <> 0 Then
               call LogEvent(strComputer)
               Exit Function
           End If
           For i = 1 to UBound(fSplit)
               Set colGroups = GetObject("WinNT://" & strComputer & "")
                   colGroups.Filter = Array("group")
                   For Each oGroup In colGroups
                       If (oGroup.Name = "Administrators") Then
                           For Each oUser in oGroup.Members
                               If LCase(oUser.Name) = LCase(fSplit(i)) Then
                                   oShell.Run oCMGR & "-u ""corp\" & fSplit(i) & """ -m " & strComputer & " -dlg ""Administrators""",0,True
                               End If
                           Next
                       End If
                   Next
           Next
       Next
   call verifyAccount(strComputer)
End Function

Let me know if that fixes it for you!

(in reply to Zenchee1)
 
 
Post #: 8
 
 RE: RemoveLocalAdmin - Excel Log - 7/19/2006 11:03:40 PM   
  Zenchee1

 

Posts: 4
Score: 0
Joined: 7/17/2006
Status: offline
The "next" did it.  I feel pretty supid for not trying that also my faith in my VB programmer has dropped since he really should have found that.  so it is working thank you very much.  Now the results were that I needed to take the AdminAccounts.txt and format it so the number of admins ds deleted and the seperator was a ";"  So my final txt looked like this

"comuputername";"username"


Works good after that.  Again thank you

_____________________________

Success through Design

(in reply to Zenchee1)
 
 
Post #: 9
 
 RE: RemoveLocalAdmin - Excel Log - 7/19/2006 11:28:10 PM   
  Country73


Posts: 712
Score: 8
Joined: 8/25/2004
From: USA
Status: offline
Glad to hear it's working correctly for you; and it's really my bad for missing that "NEXT" in my original posting of the code.

(in reply to Zenchee1)
 
 
Post #: 10
 
 RE: RemoveLocalAdmin - Excel Log - 11/29/2006 10:23:01 AM   
  zenu

 

Posts: 1
Score: 0
Joined: 11/29/2006
Status: offline
i ran the script but found that it will not actually list all users in the local admin account. am i doing something wrong? or is this an old script?

(in reply to Country73)
 
 
Post #: 11
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> RemoveLocalAdmin - Excel Log 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