Checking for unauthorized local Windows administra

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 14 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
yousuf
Posts: 8
Last visit: Tue Jan 05, 2010 9:06 pm

Checking for unauthorized local Windows administra

Post by yousuf »

Hi,Can any one please help with the script. I've never used a function and new to scripting. Error: (23, 1) Microsoft VBScript compilation error: Syntax error.************************************************************'Checking for unauthorized local Windows administratorsoption explicitdim arrRealAdmins,strComputerConst ForReading = 1Set objFSO = CreateObject("Scripting.FileSystemObject")'Text file to write resultSet oFiletxt = objFSO.CreateTextFile("c:result.txt", True)'Open a text file of computer namesSet objFile = objFSO.OpenTextFile("C:computers.txt")Do Until objFile.AtEndOfStream strComputer = objFile.ReadLine ' Configuration arrRealAdmins = Array("Administrator","Domain Admins") ' List of users that *are* supposed to be administrators' End configuration dim adminGroup, groupMember, retfunction isPermitedAdmin(MemberName) dim i for i = lbound(arrRealAdmins) to ubound(arrRealAdmins) if ucase(MemberName) = ucase(arrRealAdmins(i)) then isPermitedAdmin = true exit function end if next isPermitedAdmin = falseend functionset adminGroup = getObject("WinNT://" & strComputer & "/Administrators, group")for each groupMember in adminGroup.members if not isPermitedAdmin(groupMember.name) then ret = ret & groupMember.name & "," end ifnextif ret = "" then oFiletxt.WriteLine "No invalid local administrators found."elseret = mid(ret, 1, len(ret)-1) ' To get rid of the last comma oFiletxt.WriteLine "Members of " & objGroup.Name & ":"oFiletxt.WriteLine "& vbcrlf & retoFiletxt.Close end ifLoop************************************************************
User avatar
rasimmer
Posts: 182
Last visit: Fri Apr 25, 2014 7:00 am

Checking for unauthorized local Windows administra

Post by rasimmer »

It looks like there were several formatting issues in the script. The main issue is that you had a function inside of the loop, but there were several other errors too. I rewrote the script, give this a try and let me know if you have any other questions.


************************************************************'Checking for unauthorized local Windows administrators
Option Explicit
Const ForReading = 1
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")Dim arrRealAdmins : arrRealAdmins = Array("Administrator","Domain Admins") ' List of users that *are* supposed to be administrators'Text file to write resultDim oFiletxt : Set oFiletxt = objFSO.CreateTextFile("c:result.txt", True)'Open a text file of computer namesDim objFile : Set objFile = objFSO.OpenTextFile("C:computers.txt", ForReading, False)
Do Until objFile.AtEndOfStream Dim strComputer : strComputer = objFile.ReadLine Dim ret : ret = "" Dim adminGroup : Set adminGroup = getObject("WinNT://" & strComputer & "/Administrators, group") oFiletxt.WriteLine "Members of " & objGroup.Name & ":"
oFiletxt.WriteBlankLines(2)
Dim groupMember For Each groupMember In adminGroup.members If isPermitedAdmin(groupMember.name) = False Then oFiletxt.WriteLine ret End If Next If ret = "" Then oFiletxt.WriteLine "No invalid local administrators found." End ifLoopoFiletxt.Close
Function isPermitedAdmin(MemberName) Dim i isPermitedAdmin = False For i = LBound(arrRealAdmins) to UBound(arrRealAdmins) If UCase(MemberName) = UCase(arrRealAdmins(i)) Then isPermitedAdmin = true End if NextEnd Function
************************************************************
User avatar
yousuf
Posts: 8
Last visit: Tue Jan 05, 2010 9:06 pm

Checking for unauthorized local Windows administra

Post by yousuf »

It is not working... Error (13, 22) (null): 0x80005000.Dim adminGroup : Set adminGroup = getObject("WinNT://" & strComputer & "/Administrators, group")
User avatar
rasimmer
Posts: 182
Last visit: Fri Apr 25, 2014 7:00 am

Checking for unauthorized local Windows administra

Post by rasimmer »

There were numerous issues in the script. I have run this script on my system and it worked properly. Give it a go and let us know if you have any issues:
'************************************************************'Checking for unauthorized local Windows administrators
Option Explicit
Const ForReading = 1
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")Dim arrRealAdmins : arrRealAdmins = Array("Administrator","Domain Admins") ' List of users that *are* supposed to be administrators'Text file to write resultDim oFiletxt : Set oFiletxt = objFSO.CreateTextFile("c:result.txt", True)'Open a text file of computer namesDim objFile : Set objFile = objFSO.OpenTextFile("C:computers.txt", ForReading, False)
Do Until objFile.AtEndOfStream Dim strComputer : strComputer = Trim(objFile.ReadLine) Dim adminGroup : Set adminGroup = getObject("WinNT://" & strComputer & "/Administrators, group") oFiletxt.WriteLine "Members of " & adminGroup.Name & ":" oFiletxt.WriteBlankLines(1) Dim intCount : intCount = 0 Dim groupMember For Each groupMember In adminGroup.members If isPermittedAdmin(groupMember.name) = False Then oFiletxt.WriteLine groupMember.Name intCount = intCount + 1 End If Next If intCount = 0 Then oFiletxt.WriteLine "No invalid local administrators found." End ifLoopoFiletxt.Close
Function isPermittedAdmin(MemberName) Dim i isPermittedAdmin = False For i = LBound(arrRealAdmins) to UBound(arrRealAdmins) If UCase(MemberName) = UCase(arrRealAdmins(i)) Then isPermittedAdmin = True End if NextEnd Function
'************************************************************
User avatar
yousuf
Posts: 8
Last visit: Tue Jan 05, 2010 9:06 pm

Checking for unauthorized local Windows administra

Post by yousuf »

Yes it worked. Thank you
This topic is 14 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked