Ever seen that “Select Computer” dialog coming up and did you wonder how to have all those computer names without writing much code. There is an undocumented exported api in “ntlanman.dll” called ServerBrowseDialogA0 which is used exactly for this purpose.
[sourcecode language=’cpp’]int main()
{
// Some funky stuff
HMODULE hMod = LoadLibrary( “Kernel32.dll” );
GetConsoleWindow GCW = (GetConsoleWindow)GetProcAddress( hMod, “GetConsoleWindow” );
HWND hConsole = GCW();
SetWindowText( hConsole, “Nibu” );
// The real stuff for showing the dialog starts here
HMODULE hModule = LoadLibrary( _T( “ntlanman.dll” ));
typedef DWORD ( WINAPI *FNNTBrowseDlg )( HWND hwnd,
CHAR *pchBuffer,
DWORD cchBufSize );
FNNTBrowseDlg lpfn = 0;
CHAR szT[MAX_PATH + 1] = { 0 };
lpfn = ( FNNTBrowseDlg )GetProcAddress( hModule, “ServerBrowseDialogA0” );
// Will return zero on success, now show the dialog
const DWORD dwResult = lpfn( hConsole, szT, MAX_PATH );
// Check result
if( !dwResult )
{
stringstream sStream;
sStream < < "Selected computer name is: " << szT;
MessageBox( hConsole, sStream.str().c_str(), "Computer name", MB_OK | MB_ICONINFORMATION );
}
else
{
MessageBox( hConsole, "You didn't make any selection", "Computer name", MB_OK | MB_ICONINFORMATION );
}
FreeLibrary( hModule );
FreeLibrary( hMod );
return 0;
}// End main[/sourcecode]
Output:
Computer names are purposely not shown due to security reasons. 😉