System.IO.FileNotFoundException: The network path was not found. Exception while using DirectoryEntry object on windows 7

StackOverflow https://stackoverflow.com/questions/13955880

  •  10-12-2021
  •  | 
  •  

Question

i am trying to connect to remote windows 7 machine by using DirectoryEntry object. here is my code

DirectoryEntry obDirEntry = new DirectoryEntry("WinNT://hostName", "hostName\\testUser", "password123", AuthenticationTypes.Secure);               
            try
            {
                if (obDirEntry.Properties.Count > 0)
                {                        
                   //ok
                }
            }
            catch (Exception excp)
            {}

if i am able to connect to remote windows server 2003 machine or local windows 7 machine , then i didn't get any error. But when i am trying to connect to remote windows 7 machine then i gets exception at line if (obDirEntry.Properties.Count > 0)

 Exception :System.IO.FileNotFoundException: The network path was not found.

 at System.DirectoryServices.Interop.UnsafeNativeMethods.IAds.GetInfo()
 at System.DirectoryServices.DirectoryEntry.RefreshCache()
 at System.DirectoryServices.DirectoryEntry.FillCache(String propertyName)
 at System.DirectoryServices.PropertyCollection.get_Count()

I am able to ping that remote windows 7 m/c. firewall and UAC is also off. Problem is i am getting this problem on each remote windows 7 machine. I have tried to put ip adress in url instead of hostname, but in that case even on local machine i get above exception. nslookup command is able to resolve that remote m/c hostName. What may be reason for this ? What can be possible solution for this ? Thanks in advance !!

Was it helpful?

Solution

You need proper access to the remote registry to be able to connect to Windows 7 (&8) systems in this manner.

There is a guide here on how to successfully connect to the remote registry. It gathers all the disparate information needed - enabling file and printer sharing, enabling the remote registry service and adding the specific user that is connecting to the remote registry into the HKLM\SYSTEM\CurrentControlSet\Control\SecurePipeServers\winreg.

Once all these tasks have been performed on the remote system, you should be able to connect remotely to it using WinRT://remoteHost. I tested it on some systems I had and it works.

This is would probably all work automatically if the system was a domain bound system and the account being used to connect was a domain adminstrator account.

OTHER TIPS

I came across this recently for some of my established internal websites recently.

One item I found that was supposed to be a fix was a Microsoft Hotfix: http://support.microsoft.com/kb/2545850. You can tell if this is your issue as a server restart will temporarily remedy the error.

However in my case this did not work. Checking settings in IIS I noticed that under my sites' "Authentication" section, ASP.NET Impersonation was enabled (it was being set to "true" in the web.config). I disabled it and that resolved the issue for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top