3

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 !!

sagar
  • 1,900
  • 5
  • 30
  • 45
  • Windows 7 is not a server operating system, so it doesn't actually provide the service remotely. – Anya Shenanigans Dec 19 '12 at 16:24
  • Are those computers part of a domain? – cheesemacfly Dec 19 '12 at 17:04
  • Can you access that remote Windows 7 machine from the command line? That is, can you do `dir \\hostname\directory`? – Jim Mischel Dec 19 '12 at 17:37
  • 1
    It looks like the remote registry service needs to be running on the Windows 7 system to even have a chance of connecting to it in this manner. If you enable this service then you may have a better chance of connecting to the system (took about 10 minutes of wireshark to figure this piece out) – Anya Shenanigans Dec 19 '12 at 17:43
  • @Petesh:Thanks,Enabling Remote registry service ,worked for me. But what can be security effects of starting remote registry service ? – sagar Dec 20 '12 at 07:01
  • It increases the attack surface of the system - one more service == one more vector into the system. You need credentials to access it, so if you are using a strong password mechanisms, then you are protected in as much as password will protect you. WRT should it be enabled, for domains, it may be needed, but for the non-domain joined systems, it is just not needed. Remote access to non-managed systems' registry is just unnecessary in most cases. – Anya Shenanigans Dec 20 '12 at 09:20

2 Answers2

2

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.

Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122
2

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.

Liquid_IQ
  • 31
  • 2
  • Just came across the very same issue, however, our application had been deployed for a long time and suddenly showed these symptoms. Any idea how that might have happened? (Updates?) – Mario Tacke May 27 '15 at 15:50