skysel Posted October 24, 2008 Posted October 24, 2008 Hello again AutoIt people I'm having troubles on how to create a script, that would check a list (txt file) of computers for users of localgroup "Administrators". VBS script for checking members of localogrup administrators: Set localGroup = GetObject("WinNT://./Administrators") For Each member In localGroup.Members Wscript.Echo member.name Next Is it possible to do this using ADFunctions?
ptrex Posted October 24, 2008 Posted October 24, 2008 @skysel Maybe this can get you going : expandcollapse popup#include <array.au3> ; Initialize error handler $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") $GroupPath = InputBox("List Group Members", "Enter DOMAIN/GROUP to list: ","DOMAIN/GROUP") $avUsers = _GroupGetMembers($GroupPath) If Not @error Then _ArrayDisplay($avUsers, "Users in group") Else MsgBox(16, "Error", "Error returned: @error = " & @error) EndIf ; ------------------------------------------------------------ ; Function _GroupGetMembers($sPath) ; Call with: _GroupGetMembers($sPath) ; Where: $sPath = DOMAIN/GROUP, i.e. "MyDomain/Domain Admins" ; If Domain is not included, uses local machine, i.e. "Administrators" will be xlated to "./Administrators" ; On success returns an array of members in the specified group with [0] = count. ; For an empty group, returns [0] = 0. ; On failure sets @error. ; ------------------------------------------------------------ Func _GroupGetMembers($sPath) Local $oUser, $sRET = "", $avRET ; Check path to group $sPath = StringReplace($sPath, "\", "/") ; Don't use backslash with WMI path If Not StringInStr($sPath, "/") Then $sPath = "./" & $sPath ; Use local if no domain given ; Get group object Local $oGroup = ObjGet("WinNT://" & $sPath) If IsObj($oGroup) Then For $oUser In $oGroup.Members $sRET &= $oUser.Name & @LF ; $sRET &= $oUser.Name & "," & $oUser.mail & "," & $oUser.telephoneNumber & "," & $oUser.facsimileTelephoneNumber & @LF Next ; Split into an array for return $avRET = StringSplit(StringStripWS($sRET, 2), @LF) ; Change result for empty group [0] = 0 If $avRET[1] = "" Then Local $avRET[1] = [0] Return $avRET Else ; Error getting group object Return SetError(1, 0, 0) EndIf EndFunc ;==>_GroupGetMembers Func MyErrFunc() $HexNumber=hex($oMyError.number,8) Msgbox(0,"COM Error Test","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) SetError(1) ; to check for after this function returns Endfunc Regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New
jvanegmond Posted October 24, 2008 Posted October 24, 2008 Hi. $localgroup = ObjGet("WinNT://./Administrators") For $member In $localgroup.Members MsgBox(0,"", $member.name) Next github.com/jvanegmond
skysel Posted October 27, 2008 Author Posted October 27, 2008 Thanks for the help guys, however I will still require some help... I've been working on following issues past few days, and I've got no success: - If a computer name is not found on the network, script should continue executing and not abort - When script returns names of Administrators group members, those names should be appended to each computer name.. I modified a script a bit, so it's checking computer names from a file (200+ computers).. test2.txt is the output file with group members, without computer names along.. list-text.txt is list of computers (e.g. COMPUTERNAME\Administrators). Below is the script: expandcollapse popup#include <array.au3> #include <File.au3> $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") $sfile = "C:\test2.txt" $GroupPath = FileReadLine("C:\list-test.txt") $avUsers = _GroupGetMembers($GroupPath) If Not @error Then _FileWriteFromArray($sfile, $avUsers,1) Else MsgBox(16, "Error", "Error returned: @error = " & @error) EndIf Func _GroupGetMembers($sPath) Local $oUser, $sRET = "", $avRET ; Check path to group $sPath = StringReplace($sPath, "\", "/") ; Don't use backslash with WMI path If Not StringInStr($sPath, "/") Then $sPath = "./" & $sPath ; Use local if no domain given ; Get group object Local $oGroup = ObjGet("WinNT://" & $sPath) If IsObj($oGroup) Then For $oUser In $oGroup.Members $sRET &= $oUser.Name & @LF Next $avRET = StringSplit(StringStripWS($sRET, 2), @LF) If $avRET[1] = "" Then Local $avRET[1] = [0] Return $avRET Else Return SetError(1, 0, 0) EndIf EndFunc Func MyErrFunc() $HexNumber=hex($oMyError.number,8) Msgbox(0,"COM Error Test","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) SetError(1) ; to check for after this function returns Endfunc
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now