Здравствуйте! Проблема такая, надо получить список зарегистрированных на контроллере домена рабочих станций, причем всех, как включенных, так и выключенных( Аналог: Виндовый "Поиск в Active Directory" ). Не подскажете как? Спасибо.
msdn.microsoft.com/en-us/library/aa746468(VS.85).aspx Или где-то рядом. Поиск по msdn "Searching Active Directory"
Код (Text): var objConnection = new ActiveXObject("ADODB.Connection"); objConnection.Provider = "ADsDSOObject"; objConnection.Open("Active Directory Provider"); var objCommand = new ActiveXObject("ADODB.Command"); objCommand.ActiveConnection = objConnection; objCommand.CommandText = "SELECT Name,Location FROM 'LDAP://DC=corp,DC=company,DC=ru' WHERE objectClass='computer'" objCommand.Properties("Page Size") = 1000; objCommand.Properties("Searchscope") = 2; // ADS_SCOPE_SUBTREE var objRecordSet = objCommand.Execute(); objRecordSet.MoveFirst(); while (!objRecordSet.EOF) { WScript.Echo("Computer Name: " + objRecordSet.Fields("Name").Value); objRecordSet.MoveNext(); } А раз работает через COM то никаких проблем с портацией хоть на асм хоть на сишарп =)
К сожалению скрипты использовать не желательно, а NetServerEnum вернет только список включенных рабочих станций...
Попробуй связку функций (объявлены в Netapi32.dll): Код (Text): DsGetDcOpen DsGetDcNext DsGetDcClose либо какую-нибудь из этого списка функций (объявлены в Ntdsapi.dll): Код (Text): DsListSites DsListDomainsInSite DsListServersForDomainInSite
переписал сегодня скрипт, что был в посте #3 ан фасме. все работает, только надо не забыть изменить wstrQuery для конкретного домена. в сорцах стоит corp.company.ru Код (Text): format PE GUI 5.0 entry EntryProc include 'win32ax.inc' ; ################################################################################## section '.text' code readable executable ;===========================================================; proc EntryProc ;===========================================================; invoke CoInitialize,0 call NetEnumComputers invoke CoUninitialize invoke ExitProcess,0 endp struc GUID def { match d1-d2-d3-d4-d5, def \{ .data1 dd 0x\#d1 .data2 dw 0x\#d2 .data3 dw 0x\#d3 .data4 db 0x\#d4 shr 8,0x\#d4 and 0FFh .data5 db 0x\#d5 shr 40,0x\#d5 shr 32 and 0FFh,0x\#d5 shr 24 and 0FFh,0x\#d5 shr 16 and 0FFh,0x\#d5 shr 8 and 0FFh,0x\#d5 and 0FFh \} } S_OK = 0 S_FALSE = 1 CLSCTX_INPROC_SERVER = 1 CLSCTX_INPROC_HANDLER = 2 CLSCTX_LOCAL_SERVER = 4 CLSCTX_REMOTE_SERVER = 16 VT_EMPTY = 0 VT_NULL = 1 VT_I2 = 2 VT_I4 = 3 VT_R4 = 4 VT_R8 = 5 VT_CY = 6 VT_DATE = 7 VT_BSTR = 8 VT_DISPATCH = 9 VT_ERROR = 10 VT_BOOL = 11 VT_VARIANT = 12 VT_UNKNOWN = 13 VT_DECIMAL = 14 VT_I1 = 16 VT_UI1 = 17 VT_UI2 = 18 VT_UI4 = 19 VT_I8 = 20 VT_UI8 = 21 VT_INT = 22 VT_UINT = 23 VT_VOID = 24 VT_HRESULT = 25 VT_PTR = 26 VT_SAFEARRAY = 27 VT_CARRAY = 28 VT_USERDEFINED = 29 VT_LPSTR = 30 VT_LPWSTR = 31 VT_INT_PTR = 37 VT_UINT_PTR = 38 VT_FILETIME = 64 VT_BLOB = 65 VT_STREAM = 66 VT_STORAGE = 67 VT_STREAMED_OBJECT = 68 VT_STORED_OBJECT = 69 VT_BLOB_OBJECT = 70 VT_CF = 71 VT_CLSID = 72 VT_VECTOR = 0x1000 VT_ARRAY = 0x2000 VT_BYREF = 0x4000 VT_RESERVED = 0x8000 VT_ILLEGAL = 0xffff VT_ILLEGALMASKED = 0x0fff VT_TYPEMASK = 0x0fff struct VARIANTARG vt dw ? wReserved1 dw ? wReserved2 dw ? wReserved3 dw ? data db 8 dup (?) ends adCmdUnspecified = 0xffffffff adCmdUnknown = 0x00000008 adCmdText = 0x00000001 adCmdTable = 0x00000002 adCmdStoredProc = 0x00000004 adCmdFile = 0x00000100 adCmdTableDirect = 0x00000200 adOptionUnspecified = 0xffffffff adAsyncExecute = 0x00000010 adAsyncFetch = 0x00000020 adAsyncFetchNonBlocking = 0x00000040 adExecuteNoRecords = 0x00000080 ; ADODBConnection CLASS_ADODBConnection GUID 00000514-0000-0010-8000-00AA006D2EA4 IID_ADODBConnection GUID 00000550-0000-0010-8000-00AA006D2EA4 interface ADODBConnection,\ QueryInterface,\ ; IUnknown AddRef,\ Release,\ GetTypeInfoCount,\ ; IDispatch GetTypeInfo,\ GetIDsOfNames,\ Invoke,\ Get_Properties,\ ; _ADO Get_ConnectionString,\ ; Connection15 Set_ConnectionString,\ Get_CommandTimeout,\ Set_CommandTimeout,\ Get_ConnectionTimeout,\ Set_ConnectionTimeout,\ Get_Version,\ Close,\ Execute,\ BeginTrans,\ CommitTrans,\ RollbackTrans,\ Open,\ Get_Errors,\ Get_DefaultDatabase,\ Set_DefaultDatabase,\ Get_IsolationLevel,\ Set_IsolationLevel,\ Get_Attributes,\ Set_Attributes,\ Get_CursorLocation,\ Set_CursorLocation,\ Get_Mode,\ Set_Mode,\ Get_Provider,\ Set_Provider,\ Get_State,\ OpenSchema,\ Cancel ; _Connection ; ADODBCommand CLASS_ADODBCommand GUID 00000507-0000-0010-8000-00AA006D2EA4 IID_ADODBCommand GUID 0000054E-0000-0010-8000-00AA006D2EA4 interface ADODBCommand,\ QueryInterface,\ ; IUnknown AddRef,\ Release,\ GetTypeInfoCount,\ ; IDispatch GetTypeInfo,\ GetIDsOfNames,\ Invoke,\ Get_Properties,\ ; _ADO Get_ActiveConnection,\ ; Command15 Set_ActiveConnection,\ Set_ActiveConnection2,\ Get_CommandText,\ Set_CommandText,\ Get_CommandTimeout,\ Set_CommandTimeout,\ Get_Prepared,\ Set_Prepared,\ Execute,\ CreateParameter,\ Get_Parameters,\ Set_CommandType,\ Get_CommandType,\ Get_Name,\ Set_Name,\ Get_State,\ ; _Command Cancel ; ADODBRecordset CLASS_Recordset GUID 00000535-0000-0010-8000-00AA006D2EA4 IID_Recordset GUID 00000555-0000-0010-8000-00AA006D2EA4 interface ADODBRecordset,\ ; IUnknown QueryInterface,\ AddRef,\ Release,\ GetTypeInfoCount,\ ; IDispatch GetTypeInfo,\ GetIDsOfNames,\ Invoke,\ Get_Properties,\ ; _ADO Get_AbsolutePosition,\ ; Recordset15 Set_AbsolutePosition,\ Set_ActiveConnection,\ Set_ActiveConnection2,\ Get_ActiveConnection,\ Get_BOF,\ Get_Bookmark,\ Set_Bookmark,\ Get_CacheSize,\ Set_CacheSize,\ Get_CursorType,\ Set_CursorType,\ Get_EOF,\ Get_Fields,\ Get_LockType,\ Set_LockType,\ Get_MaxRecords,\ Set_MaxRecords,\ Get_RecordCount,\ Set_Source,\ Set_Source2,\ Get_Source,\ AddNew,\ CancelUpdate,\ Close,\ Delete,\ GetRows,\ Move,\ MoveNext,\ MovePrevious,\ MoveFirst,\ MoveLast,\ Open,\ Requery,\ xResync,\ Update,\ Get_AbsolutePage,\ Set_AbsolutePage,\ Get_EditMode,\ Get_Filter,\ Set_Filter,\ Get_PageCount,\ Get_PageSize,\ Set_PageSize,\ Get_Sort,\ Set_Sort,\ Get_Status,\ Get_State,\ xClone,\ UpdateBatch,\ CancelBatch,\ Get_CursorLocation,\ Set_CursorLocation,\ NextRecordset,\ Supports,\ Get_Collect,\ Set_Collect,\ Get_MarshalOptions,\ Set_MarshalOptions,\ Find,\ Cancel,\ ; Recordset20 Get_DataSource,\ Set_DataSource,\ Save,\ Get_ActiveCommand,\ Set_StayInSync,\ Get_StayInSync,\ GetString,\ Get_DataMember,\ Set_DataMember,\ CompareBookmarks,\ Clone,\ Resync,\ Seek,\ ; _Recordset Set_Index,\ Get_Index ; ADODBFields interface ADODBFields,\ QueryInterface,\ ; IUnknown AddRef,\ Release,\ GetTypeInfoCount,\ ; IDispatch GetTypeInfo,\ GetIDsOfNames,\ Invoke,\ Get_Count,\ ; _Collection NewEnum,\ Refresh,\ Get_Item,\ ; Fields15 Append,\ ; Fields Delete ; ADODBField interface ADODBField,\ QueryInterface,\ ; IUnknown AddRef,\ Release,\ GetTypeInfoCount,\ ; IDispatch GetTypeInfo,\ GetIDsOfNames,\ Invoke,\ Get_Properties,\ ; _ADO Get_ActualSize,\ ; Field Get_Attributes,\ Get_DefinedSize,\ Get_Name,\ Get_Type_,\ Get_Value,\ Set_Value,\ Get_Precision,\ Get_NumericScale,\ AppendChunk,\ GetChunk,\ Get_OriginalValue,\ Get_UnderlyingValue,\ Get_DataFormat,\ Set_DataFormat,\ Set_Precision,\ Set_NumericScale,\ Set_Type,\ Set_DefinedSize,\ Set_Attributes ;===========================================================; proc NetEnumComputers ;===========================================================; locals connection ADODBConnection command ADODBCommand recordset ADODBRecordset fields ADODBFields field ADODBField bstrProvider dd ? bstrDataSource dd ? bstrQuery dd ? recordset_eof dd ? value VARIANTARG endl xor eax,eax mov [connection],eax mov [command],eax mov [recordset],eax invoke SysAllocString,wstrProvider mov [bstrProvider],eax invoke SysAllocString,wstrDataSource mov [bstrDataSource],eax invoke SysAllocString,wstrQuery mov [bstrQuery],eax invoke CoCreateInstance,CLASS_ADODBConnection,0,CLSCTX_INPROC_SERVER,IID_ADODBConnection,addr connection .if eax <> S_OK invoke MessageBoxA,HWND_DESKTOP,'ADODBConnection failed.',0,MB_ICONERROR jmp .exit .endif invoke CoCreateInstance,CLASS_ADODBCommand,0,CLSCTX_INPROC_SERVER,IID_ADODBCommand,addr command .if eax <> S_OK invoke MessageBoxA,HWND_DESKTOP,'ADODBCommand failed.',0,MB_ICONERROR jmp .exit .endif cominvk connection,Set_Provider,[bstrProvider] .if eax <> S_OK invoke MessageBoxA,HWND_DESKTOP,'Set_Provider failed.',0,MB_ICONERROR jmp .exit .endif cominvk connection,Open,[bstrDataSource],0,0,0 .if eax <> S_OK invoke MessageBoxA,HWND_DESKTOP,'Open connection failed.',0,MB_ICONERROR jmp .exit .endif cominvk command,Set_ActiveConnection,[connection] .if eax <> S_OK invoke MessageBoxA,HWND_DESKTOP,'Set_ActiveConnection failed.',0,MB_ICONERROR jmp .exit .endif cominvk command,Set_CommandText,[bstrQuery] .if eax <> S_OK invoke MessageBoxA,HWND_DESKTOP,'Set_CommandText failed.',0,MB_ICONERROR jmp .exit .endif cominvk command,Execute,0,0,adCmdText,addr recordset .if eax = 0x80040E37 ; table does not exist invoke MessageBoxA,HWND_DESKTOP,'Unable to connect to a Domain Controller. Make sure that the value of wstrQuery variable is correct and try again.',0,MB_ICONERROR jmp .exit .endif .if eax <> S_OK invoke MessageBoxA,HWND_DESKTOP,'Execute command failed.',0,MB_ICONERROR jmp .exit .endif cominvk recordset,MoveFirst .if eax <> S_OK invoke MessageBoxA,HWND_DESKTOP,'MoveFirst failed.',0,MB_ICONERROR jmp .exit .endif .repeat cominvk recordset,Get_EOF,addr recordset_eof .if eax <> S_OK invoke MessageBoxA,HWND_DESKTOP,'Get_EOF failed.',0,MB_ICONERROR jmp .exit .endif cmp word [recordset_eof],0 jnz .exit cominvk recordset,Get_Fields,addr fields .if eax <> S_OK invoke MessageBoxA,HWND_DESKTOP,'Get_Fields failed.',0,MB_ICONERROR jmp .exit .endif ; put VARIANTARG struct into the stack. 1 is a column number (column "Name") cominvk fields,Get_Item,VT_I4,0,1,0,addr field .if eax <> S_OK invoke MessageBoxA,HWND_DESKTOP,'Get_Item failed.',0,MB_ICONERROR jmp .exit .endif cominvk field,Get_Value,addr value .if eax <> S_OK invoke MessageBoxA,HWND_DESKTOP,'Get_Value failed.',0,MB_ICONERROR jmp .exit .endif invoke VariantChangeType,addr value,addr value,0,VT_BSTR .if eax <> S_OK invoke MessageBoxA,HWND_DESKTOP,'Value conversion failed.',0,MB_ICONERROR jmp .exit .endif invoke MessageBoxW,HWND_DESKTOP,dword[value.data],dword[value.data],MB_ICONINFORMATION invoke VariantClear,addr value cominvk recordset,MoveNext .until word [recordset_eof] <> 0 .exit: invoke SysFreeString,[bstrProvider] invoke SysFreeString,[bstrDataSource] invoke SysFreeString,[bstrQuery] .if [recordset] cominvk recordset,Close cominvk recordset,Release .endif .if [command] cominvk command,Release .endif .if [connection] cominvk connection,Close cominvk connection,Release .endif ret endp ; ################################################################################## section '.data' data readable writeable wstrProvider du 'ADsDSOObject',0 ; 'Microsoft.Jet.OLEDB.4.0' wstrDataSource du 'Active Directory Provider',0 ; 'c:\\db1.mdb' wstrQuery du 'SELECT Name,Location FROM ''LDAP://DC=corp,DC=company,DC=ru'' WHERE objectClass=''computer''',0 ; 'SELECT * FROM Table1' ; ################################################################################## section '.idata' data import readable writeable library kernel32,'KERNEL32.DLL',\ user32,'USER32.DLL',\ ole32,'OLE32.DLL',\ oleaut32,'OLEAUT32.DLL' import_kernel32 import_user32 import ole32,\ CoCreateInstance,'CoCreateInstance',\ CoInitialize,'CoInitialize',\ CoUninitialize,'CoUninitialize' import oleaut32,\ SysAllocString,'SysAllocString',\ SysFreeString,'SysFreeString',\ VariantChangeType,'VariantChangeType',\ VariantClear,'VariantClear' ; ##################################################################################