Советы по Delphi

         

Как узнать кто висит на моей (или не моей) машине


Nomadic приводит сиплюсплюсный код:

#define STRICT #include #include #include #include void UserEnum() { BOOL keepGoing = TRUE ; DWORD entriesRead, totalEntries ; USER_INFO_2 * pInfo = NULL ; DWORD resumeHandle = 0 ; // must be 0 to start with char nameBuf[ UNLEN + 1 ] ; // constants defined in LMCONS.H char commentBuf[ MAXCOMMENTSZ + 1 ] ; WCHAR serverName[ 100 ] ; lstrcpyW( serverName, L"\\\\PDC" ) ; //L"" ) ; while ( keepGoing ) { NET_API_STATUS ret = NetUserEnum( serverName, //NULL, 2, 0, //FILTER_NORMAL_ACCOUNT, (LPBYTE *)&pInfo, // Important: ADDRESS of POINTER sizeof( USER_INFO_2 ) * 100, // requested buffer size; it may not actually allocate this much &entriesRead, &totalEntries, &resumeHandle ) ; keepGoing = ( ret == ERROR_MORE_DATA ) ; if ( ret == 0 || ret == ERROR_MORE_DATA ) { DWORD i ; for ( i = 0 ; i < entriesRead ; i++ ) { // Note that strings in the INFO structures // will ALWAYS be Unicode, regardless of // your settings! Even though they're declared // as LPTSTR, they're always LPWSTR. // I'm compiling for non-Unicode, so I // convert them to ANSI strings... // Check for NULL pointers in the INFO structure LPWSTR pName = (LPWSTR)pInfo[ i ].usri2_name ; LPWSTR pComm = (LPWSTR)pInfo[ i ].usri2_comment ; if ( pName == NULL ) { lstrcpy( nameBuf, "(no name!)" ) ; } else if ( lstrlenW( pName ) == 0 ) { lstrcpy( nameBuf, "(empty name!)" ) ; } else { WideCharToMultiByte( CP_ACP, 0, pName, -1, nameBuf, UNLEN, NULL, NULL ) ; } if ( pComm == NULL ) { lstrcpy( commentBuf, "(no comment!)" ) ; } else if ( lstrlenW( pComm ) == 0 ) { lstrcpy( commentBuf, "(empty comment!)" ) ; } else { WideCharToMultiByte( CP_ACP, 0, pComm, -1, commentBuf, MAXCOMMENTSZ, NULL, NULL ) ; } cout [001578]



Содержание раздела