Get List of Local Network Computer Names - c#

I am using visual studio 2010 and I have searched on the net for help and other people using the DirectoryEntry("WinNT:") but it doesn't seem to work for me. I can see my network workgroups and if I use DirectoryEntry("WinNT://MYWORKGROUP") I can't see any computers listed.
Please help I am not sure why it isn't working for me.
Thanks

Getting computer names from my network places:
Do not use DirectoryServices unless your sure of a domain environment. The System.DirectoryServices class is an ADSI wrapper that dosent work without an Active Directory to query against. NetServerEnum() works on workgroups and domains but dosen't guarantee the most reliable data (not all machines may show up). It relies on the Computer Browser service.

To browse the local Windows network, NetBIOS name resolution must be running and correctly configured. In a corporate network that often means the presence of a WINS server. The required components are not enabled by default on modern Windows installations.
Before trying to do anything from your own code, ensure that the infrastructure is in place. Open Windows Explorer and expand the "Network" node. If name Windows browsing is correctly you should see the list of computers on the network there. If the list is empty, the problem isn't in your code.

Related

Cannot impersonate to network drive using VS 2015 and IISExpress out of office

Working out of office using VPN to our domain with a C# web application, ASP.NET and .NET 4.5 (not MVC). My laptop is not in the domain. I have an "impersonate" statement in the web.config which all works perfectly in the office (PC there is in domain). When running on the laptop, and the code comes to connect to the UNC drive over VPN, I get "username or password is incorrect".
I've tried setting the "processModel" entry in the IISExpress applicationhost.config file to the same credentials as the impersonate statement but this makes no difference. I understood from searches that this should make the IISExpress application pool run under those credentials.
It is tricky putting the laptop in the domain for other reasons (internet not always available) and I'm not even sure this is the problem. I've also used "cmdkey" to store the network credentials locally.
Any advice would be much appreciated - I've researched this for many hours and also modified "windowsAuthentication" and "anonymousAuthentication" in the applicationhost.config file from "deny" to "Allow", and set their corresponding "modules" to true from false. Nothing makes any difference, nor does running IISExpress with admin rights. Apologies in advance if this is a stupid question, but I often have to do remote support, and I also test the impact of upgrading 3rd party components before updating the office PC, so I need to solve this if possible.

Stand alone DirectoryServices.DirectoryEntry()

I'm on a stand alone Windows 10 laptop and NOT running AD LDS or any other active directory services. I'm running IIS.
I'm trying to deeply understand what this line of code is doing and more importantly, how.
DirectoryEntry e3 = new DirectoryEntry(#"IIS://localhost/W3SVC/1/Root");
Does a windows OS fake in some sort of resolution for this method in absence of active directory?
1) First take care to note if you mean pre/port IIS7. With and after IIS7 many things changed yet, all to much, they still look alike. But there are important differences.
2) MAKE SURE you are at least running in administrative mode
run as administrator
~ or doing something better.
3) Look into .net's DirectoryServices()/DirectoryEntry() but also Microsoft.Web.Administration.ServerManager(). This is probably where you can do 90% of all you are attempting.
4) There is a windows tool cmdline exe (windows/syswow64[system32]/inetsvr/appcmd.exe) that is wonderfully helpful ~ in fact, if it is an option for your needs/environment, you might prefer to create a cmd script for all that you are trying to do. I suggest first learn this tool, then use it to extract out a lot of the IIS/Site metadata to explore what & where you are trying to get to. https://www.iis.net/configreference/system.applicationhost/applicationpools
5) Powershell has a snapin, certainly on server with IIS installed, maybe on workstations. I don't use a lot of powershell so the most i will say about that is the snapin is called WebAdministration and/or iisConsole. You may need to/prefer to manually register the snapin each time you run your script OR you might automatically register the snapin by using the IIS powershell management console.
6) For any above option always remember #2 ~ be certain you are at least running in administrative mode.
7) I know you certainly are playing in the land of IIS's metadata database ~ not the registry so much.
Local workstation: The exact mechanics when you are local to the IIS instance? I'm not sure. You might be accessing the metadata directly, you might be getting to the metadata via the IIS service, or you might be accessing the Server.exe Server service, or something else.
Remote server w/o LDAP: If you are querying a remote server not in an active directory? same as a workstation.
Remote server w/ LDAP: If you are querying a server in an AD you almost certainly are hitting the AD/LDAP service. Of course, how you are doing so might technically be via a segregate such as server.exe service running on that remote.
-- The end game is appcmd.exe, powershell, or c# Microsoft.Web.Administration, DirectoryServer(), all probably come close to doing the same thing in the background. But these are your interfaces to access that background so you don't need to think so much about the deeper implementation.
I hope this helps everyone!
Up vote it is you like this answer.

Configure loopback adapter

Tl;dr How do I access my computer's files using loopbacking?
I need to test my code with a network drive without having one installed. For that, I've installed the Microsoft Loopback Adapter. I can now access it under "Network connections".
Under its properties -> configure -> advanced I've set its network address to 192.168.0.123 .
But it doesn't seem to do anything. I can't, for example, enter that address in a browser or windows explorer and see my computer's files.
How can I achieve that? It doesn't have to be by explorer - if I can do it from C# that's fine because that's the goal anyway.
Thanks everyone. It seems it's trivial (once you know what to do...).
Just use the UNC path. No setup required. (I did share the folder through explorer's UI. But it I'm not sure that was needed.)

RPC Server Is Unavailable error and Directory does not exist

Background
I have written a utility that watches for files in a certain directory, and then copies them to defined target locations on remote machines. There is also a feature that allows stopping defined services in order to allow copying to the target.
In our work environment, these remote machines are typically VMs (we use VMWare Workstation) and the machines are part of a VM sub-domain, and are configured to use NAT networking (share the host machine's IP address). So when I say "remote" it's really referring to a VM running on the host.
Problem
For my utility, I'm trying to copy files using a UNC path to the target directory, and using the machine name get a list of services using the ServiceController.GetServices(string machineName) method.
So if you had a VM named server-1, you might be trying to copy a file to \\server-1\c$\destinationfolder. Most of the time this works, but sometimes I see an excetion because the target directory can't be found. When this happens, we also see an error when trying to get services on the remote machine - "The RPC server is unavailable."
When the VM is restarted, everything works fine... for a while.
I'm having a hard time trying to nail down the issue, because it's sporadic and doesn't affect most people. I'm wondering if it's an IP issue, where VMWare changes the IP and it's stale in the host's cache? (If I sound like I don't really know what I'm talking about here, it's only because I don't... my networking knowledge is fairly basic). When I look up issues with the 'RPC server is unavailable' error, I see a lot of answers regarding firewalls, which I don't believe is the case here. We don't run anything like McAfee internally and since it works most of the time, it doesn't seem like the cause.
Actual Questions
Anyone have any thoughts as to what might cause this problem? As a follow-up, if it is a stale IP issue, how could I recreate the issue for debugging purposes, so I can try to come up with a good way to resolve it going forward?

Search and get file information from remote workstation on a Windows domain

I need to query the file system of a remote workstation on a Windows domain. The program should search the remote file system for the existence of specific filenames and file paths. For example, assume I want to find out whether “c:\program files\mozilla\firefox.exe” or “c:\program files\chrome\chrome.exe” exists on any workstation in a domain of 10,000 machines.
What options I know:
1) Only C# code with windows impersonation using WIN32 API and using UNC path with Admin Share access like \ServerName\C$\FolderName.(I am not sure that we need to run the app from domain server to get workstation Admin Share access).
2) Using WMI with C# Management classes, get remote system access with Domain Admin credentials impersonation, then use query(s) to get the remote file information.
I have implemented both scenarios, but I am not sure which one best and performs well on real time. I have only tested with 2-3 systems network available with me.
I have questions in my mind.
1) Which option is best suits for the situation?
2) Which one is faster, safer and consistent?
Please suggest me one of those or any best option available for above requirement.
Thank You,
Ravi
No need to run this from a domain controller. With proper privs, you can run WMI queries from anywhere. In fact, pushing them to a DC would add a hop to the query and likely be slower than querying directly. If you have domain admin privs for the process, I'd just query directly to the unc path for the file existence check, and be done with it.

Categories