RemoveLocalAdmin - Excel Log

Author Message
Country73

  • Total Posts : 754
  • Scores: 10
  • Reward points : 0
  • Status: offline
RemoveLocalAdmin - Excel Log Tuesday, May 16, 2006 5:16 AM (permalink)
0
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...
 '===================================================================
 ' Title:  List all Local Admin Accounts
 ' Description: Runs from a pclist to check which accounts are setup
 '    in the local admin group.
 '    Everything is written to an Excel Worksheet. Sheet(1)
 '    will list the machine name and the accounts.
 '    Sheet(2) will list the machines that are "OFFLINE"
 '
 ' Requirements: MSExcel
 '    pclist.txt containing list of machines to run against.
 '     Each machine must be on it's own sepearate line.
 '
 ' Created by: Chris Hatt
 ' Creatd on: 05/01/06
 '====================================================================
 Set oFS = CreateObject("Scripting.FileSystemObject")
 Set oShell = WScript.CreateObject("WScript.Shell")
 Set oXLS = CreateObject("Excel.Application")
 Const PCL = "pclist.txt"
 strXLSFile = "C:\LocalAdmins.xls"
 '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 '             Force script to run in "CScript" mode
 '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 If Instr(1, WScript.FullName, "CScript", vbTextCompare) = 0 Then
     oShell.Run "cscript """ & WScript.ScriptFullName & """", 1, False
     WScript.Quit
 End If
 '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 'Deletes the old log file
 If oFS.FileExists(strXLSFile)Then
  oFS.DeleteFile strXLSFile, TRUE
 End If
 'Creation of the Excel Workbook
 oXLS.Visible = TRUE
 oXLS.Workbooks.Add
 intIndex = 2
 oXLS.Sheets(3).Delete 'This removes the 3rd worksheet since it is not in use
 'Creates the Column Headers for each page
 oXLS.Sheets(1).Cells(1,1).Value = "Computer"
 oXLS.Sheets(1).Cells(1,2).Value = "Accounts->"
 oXLS.Sheets(1).Cells(1,1).Font.Bold = TRUE
 oXLS.Sheets(1).Cells(1,2).Font.Bold = TRUE
 oXLS.Sheets(2).Cells(1,1).Value = "Computer"
 oXLS.Sheets(2).Cells(1,2).Value = "OFFLINE"
 oXLS.Sheets(2).Cells(1,1).Font.Bold = TRUE
 oXLS.Sheets(2).Cells(1,2).Font.Bold = TRUE
 'Name the worksheets
 oXLS.Sheets(1).Name = "LocalAdminAccounts"
 oXLS.Sheets(2).Name = "OFFLINE"
 
 strCount = 0
 'This is where it grabs the list of machines to run against
 If oFS.FileExists(PCL)Then
  Set file = oFS.GetFile(PCL)
  Set mc = file.OpenAsTextStream(1,-2)
   Do While Not mc.AtEndofStream
    line = mc.Readline
    strCount = strCount + 1 'This gives us a countdown for machines remaining
   Loop
   mc.Close
  Set pc = file.OpenAsTextStream(1,-2)
   Do While Not pc.AtEndOfStream
    myLine = Trim(pc.ReadLine)
    Call stripMachine(myLine,strCount)
   Loop
   pc.Close
 Else
  wscript.echo "No " & PCL & " found!" & vbcr & "Script will now close."
  wscript.quit
 End If
 'AutoFit and sort each page
 For z = 1 to 2
  oXLS.Sheets(z).Activate
  oXLS.Sheets(z).Columns.AutoFit
  oXLS.Sheets(z).Cells(1,1).Select
  Set oRange = oXLS.Range("A:Z")
  Set oRange2 = oXLS.Range("A2")
   oRange.Sort oRange2,1,,,,,,1
   '... for descending, or
   'oRange.Sort oRange2,1,,,,,,1
   '... for ascending
 Next
 oXLS.ActiveWorkbook.SaveAs strXLSFile,TRUE
 MsgBox "Finished" & vbcr & "File is located at: " & vbcr & strXLSFile,64,"Finished"
 'Functions
 '------------------------------------------------------------------------------
 FUNCTION stripMachine(myLine,strCount)
  strComputer = myLine
  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
    Else
     call verifyAccount(strComputer)
    End If
   Next
 End Function
 FUNCTION verifyAccount(strComputer)
  'Some machine may not allow you to pull this information
  On Error Resume Next
  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
      strUser = strUser & ";" & oUser.Name
     Next
    End If
   Next
   If Left(strUser,1) = ";" Then
    LUser = Len(strUser) - 1
    strUser = Mid(strUser,2,LUser)
   End If
  On Error Goto 0
  call logWrite(strComputer,strUser)
 END FUNCTION
 FUNCTION logWrite(strComputer,strUser)
  oXLS.Sheets(1).Activate
  oXLS.Cells(intIndex,1).Value = UCase(strComputer)
  If strUser = "" Then
   oXLS.Cells(intIndex,2).Value = "CANNOT BE MANAGED"
   oXLS.Cells(intIndex,1).Interior.ColorIndex = 3
   oXLS.Cells(intIndex,2).Interior.ColorIndex = 3
  Else
  sSplit = Split(strUser,";")
  For A = 1 to UBound(sSplit)
  Next
  For c = 2 to A
   x = c - 2
   oXLS.Cells(intIndex,c).Value = UCase(sSplit(x))
  Next
  End If
  intIndex = intIndex + 1
  oXLS.Cells(intIndex,1).Select
 END FUNCTION
 FUNCTION LogEvent(strComputer)
  oXLS.Sheets(2).Activate
  oXLS.Cells(intIndex,1).Interior.ColorIndex = 10
  oXLS.Cells(intIndex,2).Interior.ColorIndex = 10
  oXLS.Cells(intIndex,1).Value = UCase(strComputer)
  oXLS.Cells(intIndex,2).Value = "OFFLINE"
  intIndex = intIndex + 1
  oXLS.Cells(intIndex,1).Select
 End Function
 

 
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"
 '===================================================================
 ' Title:  Create Admin Remove List
 ' Description: Reads the Excel Worksheet to create a text file for
 '    removing the local admin accounts.
 '    (Used prior to "RemoveAdminAccount.vbs")
 '    This was created because upper management wanted details
 '    for each step in this process (auditing purposes).
 '
 ' Requirements: MSExcel
 '
 ' Created by: Chris Hatt
 ' Creatd on: 05/01/06
 '====================================================================
 Set oFS = CreateObject("Scripting.FileSystemObject")
 Set oExcel = CreateObject("Excel.Application")
 Set oWorkbook = oExcel.Workbooks.Open("C:\LocalAdmins.xls") 'Must use full path to Excel file
 Const OUTPUT = "AdminAccounts.txt"
 If oFS.FileExists("old" & OUTPUT)Then
  oFS.DeleteFile "old" & OUTPUT, True
 ElseIf oFS.FileExists(OUTPUT)Then
  oFS.MoveFile OUTPUT,"old" & OUTPUT
 End If
 'Skip the "Header" Row; skip the machine name
 intRow = 2
 intCol = 2
 oExcel.Sheets(1).Activate
 Set x = oFS.OpenTextFile(OUTPUT,8,True)
 Do Until oExcel.Cells(intRow,1).Value = ""
  Do Until oExcel.Cells(intRow,intCol).Value = ""
   aAccount = aAccount & vbTab & oExcel.Cells(intRow,intCol).Value
   intCol = intCol + 1
  Loop
  strCount = intCol - 2
  If aAccount <> "" Then
   x.WriteLine strCount & vbTab & oExcel.Cells(intRow,1).Value & aAccount
  End If
  strTotal = strTotal + strCount
  intRow = intRow + 1
  intCol = 2
  aAccount = ""
 Loop
  x.WriteLine
  x.WriteLine "Total Accounts:" & vbTab & strTotal
  x.Close
 strTotal = ""
 Set x = Nothing
 oExcel.Quit
 MsgBox "Done"
 

 
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"
 '===================================================================
 ' Title:  Remove Local Admin Accounts
 ' Description: Runs from RemoveAdmin.txt (a pclist) with the list of
 '    accounts that need to be removed.
 '    MachineName;Account;Account;etc...
 '
 ' Requirements: CUSRMGR.EXE
 '    This command-line tool enables editing of many of the properties
 '    available through the Local Users and Groups, a Microsoft® Windows®
 '    2000 system tool that is part of the Computer Management MMC snap-in.
 '    With CusrMgr, you can rename or delete users, set passwords, and set
 '    or reset other user properties.
 '
 '    MSExcel
 '
 ' Created by: Chris Hatt
 ' Creatd on: 05/01/06
 '====================================================================
  
 Set oFS = CreateObject("Scripting.FileSystemObject")
 Set oShell = WScript.CreateObject("WScript.Shell")
 Set oXLS = CreateObject("Excel.Application")
 Const PCL = "AdminAccounts.txt"
 Const oCMGR = "cusrmgr.exe "
 strXLSFile = "C:\LocalAdminRemain.xls"
 '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 '             Force script to run in "CScript" mode
 '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 If Instr(1, WScript.FullName, "CScript", vbTextCompare) = 0 Then
     oShell.Run "cscript """ & WScript.ScriptFullName & """", 1, False
     WScript.Quit
 End If
 '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 If oFS.FileExists(strXLSFile)Then
  oFS.DeleteFile strXLSFile, TRUE
 End If
 oXLS.Visible = TRUE
 oXLS.Workbooks.Add
 intIndex = 2
 oXLS.Sheets(3).Delete
 oXLS.Sheets(1).Cells(1,1).Value = "Computer"
 oXLS.Sheets(1).Cells(1,2).Value = "Accounts->"
 oXLS.Sheets(1).Cells(1,1).Font.Bold = TRUE
 oXLS.Sheets(1).Cells(1,2).Font.Bold = TRUE
 oXLS.Sheets(2).Cells(1,1).Value = "Computer"
 oXLS.Sheets(2).Cells(1,2).Value = "OFFLINE"
 oXLS.Sheets(2).Cells(1,1).Font.Bold = TRUE
 oXLS.Sheets(2).Cells(1,2).Font.Bold = TRUE
 'Name the worksheets
 oXLS.Sheets(1).Name = "LocalAdminAccounts"
 oXLS.Sheets(2).Name = "OFFLINE"
 
 strCount = 0
 If oFS.FileExists(PCL)Then
  Set file = oFS.GetFile(PCL)
  Set mc = file.OpenAsTextStream(1,-2)
   Do While Not mc.AtEndofStream
    line = mc.Readline
    strCount = strCount + 1
   Loop
   mc.Close
  Set pc = file.OpenAsTextStream(1,-2)
   Do While Not pc.AtEndOfStream
    myLine = Trim(pc.ReadLine)
    Call stripMachine(myLine,strCount)
   Loop
   pc.Close
 Else
  wscript.echo "No " & PCL & " found!" & vbcr & "Script will now close."
  wscript.quit
 End If
 'AutoFit and sort our pages
 For z = 1 to 2
  oXLS.Sheets(z).Activate
  oXLS.Sheets(z).Columns.AutoFit
  oXLS.Sheets(z).Cells(1,1).Select
  Set oRange = oXLS.Range("A:Z")
  Set oRange2 = oXLS.Range("B1")
   oRange.Sort oRange2,1,,,,,,1
   '... for descending, or
   'oRange.Sort oRange2,1,,,,,,1
   '... for ascending
 Next
 oXLS.ActiveWorkbook.SaveAs strXLSFile,TRUE
 MsgBox "Finished" & vbcr & "File is located at: " & vbcr & strXLSFile,64,"Finished"
 'Functions
 '------------------------------------------------------------------------------
 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
 FUNCTION verifyAccount(strComputer)
  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
      strUser = strUser & ";" & oUser.Name
     Next
    End If
   Next
   If Left(strUser,1) = ";" Then
    LUser = Len(strUser) - 1
    strUser = Mid(strUser,2,LUser)
   End If
   call logWrite(strComputer,strUser)
 END FUNCTION
 FUNCTION logWrite(strComputer,strUser)
  oXLS.Sheets(1).Activate
  oXLS.Cells(intIndex,1).Value = strComputer
  sSplit = Split(strUser,";")
  For A = 1 to UBound(sSplit)
  Next
  For c = 2 to A
   x = c - 2
   oXLS.Cells(intIndex,c).Value = sSplit(x)
  Next
  intIndex = intIndex + 1
  oXLS.Cells(intIndex,1).Select
 END FUNCTION
 FUNCTION LogEvent(strComputer)
  oXLS.Sheets(2).Activate
  oXLS.Cells(intIndex,1).Interior.ColorIndex = 10
  oXLS.Cells(intIndex,2).Interior.ColorIndex = 10
  oXLS.Cells(intIndex,1).Value = strComputer
  oXLS.Cells(intIndex,2).Value = "OFFLINE"
  intIndex = intIndex + 1
  oXLS.Cells(intIndex,1).Select
 End Function
 

 
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.
 
#1
    Country73

    • Total Posts : 754
    • Scores: 10
    • Reward points : 0
    • Status: offline
    RE: RemoveLocalAdmin - Excel Log Friday, May 19, 2006 7:22 AM (permalink)
    0
    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

     '===================================================================
     ' Title:  Remove Local Admin Accounts
     ' Description: Runs from RemoveAdmin.txt (a pclist) with the list of
     '    accounts that need to be removed.
     '    MachineName;Account;Account;etc...
     '
     ' Requirements: CUSRMGR.EXE
     '    This command-line tool enables editing of many of the properties
     '    available through the Local Users and Groups, a Microsoft® Windows®
     '    2000 system tool that is part of the Computer Management MMC snap-in.
     '    With CusrMgr, you can rename or delete users, set passwords, and set
     '    or reset other user properties.
     '
     '    MSExcel
     '
     ' Created by: Chris Hatt
     ' Creatd on: 05/01/06
     '====================================================================
     
     Set oFS = CreateObject("Scripting.FileSystemObject")
     Set oShell = WScript.CreateObject("WScript.Shell")
     Set oXLS = CreateObject("Excel.Application")
     Const PCL = "AdminAccounts.txt"
     Const oCMGR = "cusrmgr.exe "
     strXLSFile = "C:\LocalAdminRemain.xls"
     '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     '             Force script to run in "CScript" mode
     '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     If Instr(1, WScript.FullName, "CScript", vbTextCompare) = 0 Then
       oShell.Run "cscript """ & WScript.ScriptFullName & """", 1, False
       WScript.Quit
     End If
     '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     If oFS.FileExists(strXLSFile)Then
        oFS.DeleteFile strXLSFile, TRUE
     End If
     
     oXLS.Visible = TRUE
     oXLS.Workbooks.Add
     intIndex = 2
     oXLS.Sheets(3).Delete
     oXLS.Sheets(1).Cells(1,1).Value = "Computer"
     oXLS.Sheets(1).Cells(1,2).Value = "Accounts->"
     oXLS.Sheets(1).Cells(1,1).Font.Bold = TRUE
     oXLS.Sheets(1).Cells(1,2).Font.Bold = TRUE
     oXLS.Sheets(2).Cells(1,1).Value = "Computer"
     oXLS.Sheets(2).Cells(1,2).Value = "OFFLINE"
     oXLS.Sheets(2).Cells(1,1).Font.Bold = TRUE
     oXLS.Sheets(2).Cells(1,2).Font.Bold = TRUE
     'Name the worksheets
     oXLS.Sheets(1).Name = "LocalAdminAccounts"
     oXLS.Sheets(2).Name = "OFFLINE"
     
     strCount = 0
     If oFS.FileExists(PCL)Then
        Set file = oFS.GetFile(PCL)
        Set mc = file.OpenAsTextStream(1,-2)
            Do While Not mc.AtEndofStream
                line = mc.Readline
                strCount = strCount + 1
            Loop
            mc.Close
        Set pc = file.OpenAsTextStream(1,-2)
            Do While Not pc.AtEndOfStream
                myLine = Trim(pc.ReadLine)
                Call stripMachine(myLine,strCount)
            Loop
            pc.Close
     Else
        wscript.echo "No " & PCL & " found!" & vbcr & "Script will now close."
        wscript.quit
     End If
     'AutoFit and sort our pages
     For z = 1 to 2
        oXLS.Sheets(z).Activate
        oXLS.Sheets(z).Columns.AutoFit
        oXLS.Sheets(z).Cells(1,1).Select
        Set oRange = oXLS.Range("A:Z")
        Set oRange2 = oXLS.Range("B1")
            oRange.Sort oRange2,1,,,,,,1
            '... for descending, or
            'oRange.Sort oRange2,1,,,,,,1
            '... for ascending
     Next
     oXLS.ActiveWorkbook.SaveAs strXLSFile,TRUE
     MsgBox "Finished" & vbcr & "File is located at: " & vbcr & strXLSFile,64,"Finished"
     'Functions
     '------------------------------------------------------------------------------
     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
     
     FUNCTION verifyAccount(strComputer)
        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
                        strUser = strUser & ";" & oUser.Name
                    Next
                End If
            Next
            If Left(strUser,1) = ";" Then
                LUser = Len(strUser) - 1
                strUser = Mid(strUser,2,LUser)
            End If
        call logWrite(strComputer,strUser)
     END FUNCTION
     
     FUNCTION logWrite(strComputer,strUser)
        oXLS.Sheets(1).Activate
        oXLS.Cells(intIndex,1).Value = strComputer
        sSplit = Split(strUser,";")
        For A = 1 to UBound(sSplit)
        Next
        For c = 2 to A
            x = c - 2
            oXLS.Cells(intIndex,c).Value = sSplit(x)
        Next
        intIndex = intIndex + 1
        oXLS.Cells(intIndex,1).Select
     END FUNCTION
     
     FUNCTION LogEvent(strComputer)
        oXLS.Sheets(2).Activate
        oXLS.Cells(intIndex,1).Interior.ColorIndex = 10
        oXLS.Cells(intIndex,2).Interior.ColorIndex = 10
        oXLS.Cells(intIndex,1).Value = strComputer
        oXLS.Cells(intIndex,2).Value = "OFFLINE"
        intIndex = intIndex + 1
        oXLS.Cells(intIndex,1).Select
     End Function
     


    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 on Wednesday, July 19, 2006 8:35 AM>
     
    #2
      Zenchee1

      • Total Posts : 4
      • Scores: 0
      • Reward points : 0
      • Joined: 7/17/2006
      • Status: offline
      RE: RemoveLocalAdmin - Excel Log Monday, July 17, 2006 6:42 AM (permalink)
      0
      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
       
      #3
        Country73

        • Total Posts : 754
        • Scores: 10
        • Reward points : 0
        • Status: offline
        RE: RemoveLocalAdmin - Excel Log Tuesday, July 18, 2006 3:52 AM (permalink)
        0
        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?
         
        #4
          Zenchee1

          • Total Posts : 4
          • Scores: 0
          • Reward points : 0
          • Joined: 7/17/2006
          • Status: offline
          RE: RemoveLocalAdmin - Excel Log Wednesday, July 19, 2006 3:37 AM (permalink)
          0
          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
           
          #5
            Country73

            • Total Posts : 754
            • Scores: 10
            • Reward points : 0
            • Status: offline
            RE: RemoveLocalAdmin - Excel Log Wednesday, July 19, 2006 6:08 AM (permalink)
            0
            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.
             
            #6
              Zenchee1

              • Total Posts : 4
              • Scores: 0
              • Reward points : 0
              • Joined: 7/17/2006
              • Status: offline
              RE: RemoveLocalAdmin - Excel Log Wednesday, July 19, 2006 7:25 AM (permalink)
              0
              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
               
              #7
                Country73

                • Total Posts : 754
                • Scores: 10
                • Reward points : 0
                • Status: offline
                RE: RemoveLocalAdmin - Excel Log Wednesday, July 19, 2006 8:30 AM (permalink)
                0
                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!
                 
                #8
                  Zenchee1

                  • Total Posts : 4
                  • Scores: 0
                  • Reward points : 0
                  • Joined: 7/17/2006
                  • Status: offline
                  RE: RemoveLocalAdmin - Excel Log Thursday, July 20, 2006 12:03 AM (permalink)
                  0
                  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
                   
                  #9
                    Country73

                    • Total Posts : 754
                    • Scores: 10
                    • Reward points : 0
                    • Status: offline
                    RE: RemoveLocalAdmin - Excel Log Thursday, July 20, 2006 12:28 AM (permalink)
                    0
                    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.
                     
                    #10
                      zenu

                      • Total Posts : 1
                      • Scores: 0
                      • Reward points : 0
                      • Joined: 11/29/2006
                      • Status: offline
                      RE: RemoveLocalAdmin - Excel Log Wednesday, November 29, 2006 11:23 AM (permalink)
                      0
                      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?
                       
                      #11

                        Online Bookmarks Sharing: Share/Bookmark

                        Jump to:

                        Current active users

                        There are 0 members and 1 guests.

                        Icon Legend and Permission

                        • 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
                        • Read Message
                        • Post New Thread
                        • Reply to message
                        • Post New Poll
                        • Submit Vote
                        • Post reward post
                        • Delete my own posts
                        • Delete my own threads
                        • Rate post

                        2000-2012 ASPPlayground.NET Forum Version 3.9