Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / May 2004

Tip: Looking for answers? Try searching our database.

Trouble enumerating/selecting a server on the LAN

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ken Allen - 17 May 2004 15:15 GMT
I am relatively new to Windows API programming, and even more new to .Net
programming. I like most of what I see, but there are still some parts that
Microsoft seems to have gone out of their way to make as complicated as
possible.

All I want to do is present a list of the servers on the LAN that are
running a copy of my .Net service and permit the user to select one of those
servers. THis basically breaks down into two parts: generating/displaying
the list of servers on the network; and determining which of those servers
is running my service (there may be zero or more, even all of them).

Some friends came across the following code that is an excerpt from some
older C++ code (that is still working) that is used to display a dialog that
permits the user to select a specific server on the LAN, regardless of the
domains. This uses a supplied Microsoft dialog from the Shell32.DLL
component to display the sub-tree of the standard file explorer.
Unfortunately, neither they nor I are clear on how this could be converted
in C# (one of our goals is to avoid unmanaged code if at all possible,
although unsafe code is considered acceptable; and we want all code written
in C# if at all possible). Can someone suggest how this could be translated
to C#? Some of this involves COM objects (pFolder in this code), and I have
barely started to figure out how to deal with this level of communication.

//-------------------------------------
 BROWSEINFO  browseInfo = {0};
 LPITEMIDLIST pidlRoot = NULL;
 LPITEMIDLIST pidlSelected= NULL;
 LPMALLOC  pMalloc  = NULL;
 SHGetMalloc(&pMalloc);
 CComPtr<IShellFolder> pFolder;
 SHGetDesktopFolder(&pFolder);
 pFolder->ParseDisplayName(NULL, NULL,
L"::{208D2C60-3AEA-1069-A2D7-08002B30309D}\\EntireNetwork", NULL, &pidlRoot,
NULL);
 browseInfo.hwndOwner  = m_hWnd;
 browseInfo.pidlRoot   = pidlRoot;
 browseInfo.pszDisplayName = ComputerName;
 browseInfo.lpszTitle  = _T("Please choose the server to be connected");
 browseInfo.ulFlags   = BIF_BROWSEFORCOMPUTER | BIF_EDITBOX | BIF_VALIDATE;
 browseInfo.lpfn    = BrowseCallbackProc;
 browseInfo.lParam   = 0;
 if(pidlRoot)
  pidlSelected = SHBrowseForFolder(&browseInfo);
 if(!pidlSelected)   ////user selected Cancel in Browse Dialog
  ComputerName[0] = 0;
 if(pidlRoot)
  pMalloc->Free(pidlRoot);
 pMalloc->Release();
//-------------------------------------

Of course, I would prefer to simply retrieve a list of all servers on the
LAN, possibly prefixed by the domain since we run more than one domain, and
then permit the user to select from my list, but I cannot fund any other
method for enumerating the servers on the LAN. If I could do this, then the
next step would be to determine whether my service is running on each of
those systems, thus permitting me to present a list to the user that
contains only those systems that are appropriate. This would really be a
nice touch, and I am willing to live with the selection of a server system
and then let the user know whether it was a bad selection or not.

-ken
Mattias Sj?gren - 17 May 2004 16:10 GMT
Ken,

The SHBrowseForFolder API is wrapped in the managed
FolderBrowserDialog component.

But it only exposes a subset of the SHBrowseForFolder features. I
don't think can get it to browse for a computer
(BIF_BROWSEFORCOMPUTER) or set the root node to Entire Network without
at least calling some unmanaged code.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Ken Allen - 17 May 2004 16:50 GMT
So close, and yet....

There are references in the MSDN to something called the FolderNameEditor,
which seems to contain the definitions of the type I am seeking, but it is
marked as not being for use from client code. I am not certain what this is
used for or how to get access to it, thus I am left attempting to figure out
how to map the original code I posted.

-Ken

> Ken,
>
[quoted text clipped - 7 lines]
>
> Mattias

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.