-1
string strPath = "LDAP://" + dcip;
DirectoryEntry de;
if (String.IsNullOrEmpty(username))
            {
                de = new DirectoryEntry(strPath);
            }
            else
            {
                de = new DirectoryEntry(strPath, username, password);
            }
            

DirectorySearcher deSearch = new DirectorySearcher(de);
deSearch.Filter = "(objectClass=domainDNS)";
deSearch.SearchScope = SearchScope.Subtree;
SearchResult result = deSearch.FindOne();
return result.Properties["distinguishedName"][0].ToString();

this can run in the domain user's cmd, but when run it in the system privilege's cmd,it return the error

System.Runtime.InteropServices.COMException (0x80005000): 未知错误(0x80005000)
   在 System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
   在 System.DirectoryServices.DirectoryEntry.Bind()
   在 System.DirectoryServices.DirectoryEntry.get_AdsObject()
   在 System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
   在 System.DirectoryServices.DirectorySearcher.FindOne()

the powerview.ps1 use the same code with it,but powerview can run in the domain user's cmd and also the system privilege cmd

Ouroborus
  • 16,237
  • 4
  • 39
  • 62
Szz9527
  • 1
  • 1

1 Answers1

0

I hava found the bug! In my code,dcip = Environment.GetEnvironmentVariable("USERDNSDOMAIN"); But the env USERDNSDOMAIN is not same between the user and the system

Szz9527
  • 1
  • 1
  • 1
    So, the problem is solved now? Please consider deleting this question then, because nowhere in the post is shown where line `dcip = Environment.GetEnvironmentVariable("USERDNSDOMAIN")` fits in the code.. – Theo Dec 23 '22 at 12:05