Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Enumerate local pcs , workgroups etc...(PLEASE HELP)

Enumerate local pcs , workgroups etc...(PLEASE HELP)

Scheduled Pinned Locked Moved C#
tutorialcsharphelpquestion
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    giddy_guitarist
    wrote on last edited by
    #1

    Hie, i need to know how to enumerate all pcs.. connected locally to the users computer.. also i need to display this information in a treeview.. .. i need to show the workgroups and the pcs in them....and also list all the mapped drives .... i have C# 2005 .. .NET 2.0 so i'll need to know how to do it with System.Net(i think.. i jst started C#) would someone give me a WELL COMMENTED example code.. or perhaps a link to an article or tutorial?? i got no answer on the MSDN forums so PLEASE HELP:^) Thanx Gideon

    N 1 Reply Last reply
    0
    • G giddy_guitarist

      Hie, i need to know how to enumerate all pcs.. connected locally to the users computer.. also i need to display this information in a treeview.. .. i need to show the workgroups and the pcs in them....and also list all the mapped drives .... i have C# 2005 .. .NET 2.0 so i'll need to know how to do it with System.Net(i think.. i jst started C#) would someone give me a WELL COMMENTED example code.. or perhaps a link to an article or tutorial?? i got no answer on the MSDN forums so PLEASE HELP:^) Thanx Gideon

      N Offline
      N Offline
      Nader Elshehabi
      wrote on last edited by
      #2

      Hello

      giddy_guitarist wrote:

      i jst started C#

      Just started C# and you want to map a network?!! Did you try MSDN library -not the forums- Anyway, most of what you need is in the System.Net.NetworkInformation namespace, especially IPGlobalProperties class. Look them up in your MSDN documentations.

      giddy_guitarist wrote:

      would someone give me a WELL COMMENTED example code

      Try the examples of MSDN in the above classes. If you're stuck with something, we are here. Regards:rose:

      G 2 Replies Last reply
      0
      • N Nader Elshehabi

        Hello

        giddy_guitarist wrote:

        i jst started C#

        Just started C# and you want to map a network?!! Did you try MSDN library -not the forums- Anyway, most of what you need is in the System.Net.NetworkInformation namespace, especially IPGlobalProperties class. Look them up in your MSDN documentations.

        giddy_guitarist wrote:

        would someone give me a WELL COMMENTED example code

        Try the examples of MSDN in the above classes. If you're stuck with something, we are here. Regards:rose:

        G Offline
        G Offline
        giddy_guitarist
        wrote on last edited by
        #3

        http://msdn2.microsoft.com/en-us/library/system.net.networkinformation.aspx# think i got the right one.. but its prety hi-fi:doh:..... i still have to complete the Advanced section in my book(wrox beginnin C# 05) which of course covers a little on net clasess.. i'll get back to this after that i . :) Thanx ;) Gideon

        1 Reply Last reply
        0
        • N Nader Elshehabi

          Hello

          giddy_guitarist wrote:

          i jst started C#

          Just started C# and you want to map a network?!! Did you try MSDN library -not the forums- Anyway, most of what you need is in the System.Net.NetworkInformation namespace, especially IPGlobalProperties class. Look them up in your MSDN documentations.

          giddy_guitarist wrote:

          would someone give me a WELL COMMENTED example code

          Try the examples of MSDN in the above classes. If you're stuck with something, we are here. Regards:rose:

          G Offline
          G Offline
          giddy_guitarist
          wrote on last edited by
          #4

          hey.. listen.. i did extensive readin on System.Net IPGlobalProperties-> Provides information about the network connectivity of the local computer. .. i want to enum. neworks remember... AND i found some code that claims to enum. networks with System.DirectoryServices... .BUT i dont understand any of the code cuz... well its not commented at ALL! it was originally in VB.NET... i got someone to port it to C# .. but the problme is i CAN:T check if it works on my PC!!.. cuz i dont hav networks.. COULD SOMEONE PLEASE TELL ME IF THE FOLLOWING CODE WORKS!/? private void btnList_Click(object sender, EventArgs e) { DirectoryEntry entryRoot = new DirectoryEntry("WinNT://" + this.tbComputerName.Text.ToUpper(), "", "", AuthenticationTypes.None); DirectoryEntries memberEntries = entryRoot.Children; this.lvUsersGroups.SmallImageList = this.ImageList1; foreach (DirectoryEntry member in memberEntries) { if(member.SchemaClassName.Equals("User")) this.lvUsersGroups.Items.Add(member.Name, 0); if(member.SchemaClassName.Equals("Group")) this.lvUsersGroups.Items.Add(member.Name, 1); } } You will, of course, need to wire up btnList's Click event to call the above handler if you haven't already done so: this.btnList.Click += new System.EventHandler(this.btnList_Click); heres where i got the original code - > http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=3213&lngWId=10[^] PLEASE TELL ME IF EITHER ONE DOES THE JOB? Thanx Gideon

          N 1 Reply Last reply
          0
          • G giddy_guitarist

            hey.. listen.. i did extensive readin on System.Net IPGlobalProperties-> Provides information about the network connectivity of the local computer. .. i want to enum. neworks remember... AND i found some code that claims to enum. networks with System.DirectoryServices... .BUT i dont understand any of the code cuz... well its not commented at ALL! it was originally in VB.NET... i got someone to port it to C# .. but the problme is i CAN:T check if it works on my PC!!.. cuz i dont hav networks.. COULD SOMEONE PLEASE TELL ME IF THE FOLLOWING CODE WORKS!/? private void btnList_Click(object sender, EventArgs e) { DirectoryEntry entryRoot = new DirectoryEntry("WinNT://" + this.tbComputerName.Text.ToUpper(), "", "", AuthenticationTypes.None); DirectoryEntries memberEntries = entryRoot.Children; this.lvUsersGroups.SmallImageList = this.ImageList1; foreach (DirectoryEntry member in memberEntries) { if(member.SchemaClassName.Equals("User")) this.lvUsersGroups.Items.Add(member.Name, 0); if(member.SchemaClassName.Equals("Group")) this.lvUsersGroups.Items.Add(member.Name, 1); } } You will, of course, need to wire up btnList's Click event to call the above handler if you haven't already done so: this.btnList.Click += new System.EventHandler(this.btnList_Click); heres where i got the original code - > http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=3213&lngWId=10[^] PLEASE TELL ME IF EITHER ONE DOES THE JOB? Thanx Gideon

            N Offline
            N Offline
            Nader Elshehabi
            wrote on last edited by
            #5

            Hello Easy Tiger!!:-D Well, yes it works, and shows my shared network printer if supplied with the computer name that's connected to the printer. Well done!! I thought you wanted to enumerate connected PCs. What this code does is to enumerate shared folders on a Pc name that you supply!! What good is that for you? Otherwise from where do you get the this.tbComputerName?? As for the network problem. If you don't have more that one computer, you can download Microsoft's Virtual PC 2004 for free, and make a virtual network between your machine and the "Virtual PCs". This way you can test and modify you code step by step on your "Virtual network". Google for "Microsoft Virtual PC".

            Regards:rose:

            G 1 Reply Last reply
            0
            • N Nader Elshehabi

              Hello Easy Tiger!!:-D Well, yes it works, and shows my shared network printer if supplied with the computer name that's connected to the printer. Well done!! I thought you wanted to enumerate connected PCs. What this code does is to enumerate shared folders on a Pc name that you supply!! What good is that for you? Otherwise from where do you get the this.tbComputerName?? As for the network problem. If you don't have more that one computer, you can download Microsoft's Virtual PC 2004 for free, and make a virtual network between your machine and the "Virtual PCs". This way you can test and modify you code step by step on your "Virtual network". Google for "Microsoft Virtual PC".

              Regards:rose:

              G Offline
              G Offline
              giddy_guitarist
              wrote on last edited by
              #6

              oh hey thats just what i needed..! virtual PC!.. .. thanx!:) well .. yes.. i want to enum. pcs. .. before i started c# , i somehow figured out how to enum with the WNetOpenEum , and its companion API!... IN VB6 ... so do u think i should just go for enumerating with API , or can i do it in system.net or system.directoryservices... i got an offer to make booking application.. my boss has around 3-4 pcs..and the app. should basically just list the full path to all availiable pcs.... if theres no way with the .NET classes .. would u happen to know a tute for: 1. using simple API in C# 2. using the WNetOpenEnum in C# Gideon

              N 1 Reply Last reply
              0
              • G giddy_guitarist

                oh hey thats just what i needed..! virtual PC!.. .. thanx!:) well .. yes.. i want to enum. pcs. .. before i started c# , i somehow figured out how to enum with the WNetOpenEum , and its companion API!... IN VB6 ... so do u think i should just go for enumerating with API , or can i do it in system.net or system.directoryservices... i got an offer to make booking application.. my boss has around 3-4 pcs..and the app. should basically just list the full path to all availiable pcs.... if theres no way with the .NET classes .. would u happen to know a tute for: 1. using simple API in C# 2. using the WNetOpenEnum in C# Gideon

                N Offline
                N Offline
                Nader Elshehabi
                wrote on last edited by
                #7

                Hello

                giddy_guitarist wrote:

                i got an offer to make booking application

                Congratulations!

                giddy_guitarist wrote:

                just list the full path to all availiable pcs....

                All right!! Here is the code:

                IPGlobalProperties MyIP = IPGlobalProperties.GetIPGlobalProperties();
                string RemoteComputer = "";
                foreach(TcpConnectionInformation Con in MyIP.GetActiveTcpConnections())
                {
                try { RemoteComputer = Dns.Resolve(Con.RemoteEndPoint.Address.ToString()).HostName; }
                catch { /*Handle errors here*/}
                if (RemoteComputer.Length == 0)
                continue;
                if (!listBox2.Items.Contains(RemoteComputer))
                {
                listBox2.Items.Add(RemoteComputer);
                }
                }

                This should enum all tcp connections -including those on your LAN-. To identify those on the lan use there IP address. They shouild be similar, first 3 numbers are usually the same eg. 178.65.32.103 178.65.32.106 178.65.32.201 178.65.32.305

                giddy_guitarist wrote:

                just list the full path to all availiable pcs....

                Simply: @"\\" + RemoteComputer

                giddy_guitarist wrote:

                using simple API in C#

                You are talking about P/Invoke. There are tons of articles about this topic here in CP

                Regards:rose:

                G 1 Reply Last reply
                0
                • N Nader Elshehabi

                  Hello

                  giddy_guitarist wrote:

                  i got an offer to make booking application

                  Congratulations!

                  giddy_guitarist wrote:

                  just list the full path to all availiable pcs....

                  All right!! Here is the code:

                  IPGlobalProperties MyIP = IPGlobalProperties.GetIPGlobalProperties();
                  string RemoteComputer = "";
                  foreach(TcpConnectionInformation Con in MyIP.GetActiveTcpConnections())
                  {
                  try { RemoteComputer = Dns.Resolve(Con.RemoteEndPoint.Address.ToString()).HostName; }
                  catch { /*Handle errors here*/}
                  if (RemoteComputer.Length == 0)
                  continue;
                  if (!listBox2.Items.Contains(RemoteComputer))
                  {
                  listBox2.Items.Add(RemoteComputer);
                  }
                  }

                  This should enum all tcp connections -including those on your LAN-. To identify those on the lan use there IP address. They shouild be similar, first 3 numbers are usually the same eg. 178.65.32.103 178.65.32.106 178.65.32.201 178.65.32.305

                  giddy_guitarist wrote:

                  just list the full path to all availiable pcs....

                  Simply: @"\\" + RemoteComputer

                  giddy_guitarist wrote:

                  using simple API in C#

                  You are talking about P/Invoke. There are tons of articles about this topic here in CP

                  Regards:rose:

                  G Offline
                  G Offline
                  giddy_guitarist
                  wrote on last edited by
                  #8

                  Nader Elshehabi wrote:

                  giddy_guitarist wrote: i got an offer to make booking application Congratulations!

                  thanx ...hehe its the first offer i've got! well my internet connection broke down.. thats why . .i'm replyin so late!... thanx SO MUCH!!!!:):-D:):) .. !.. .the code works a treat! ..dunno how to thank you!!!! Gideon

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups