Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7195603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:36:39+00:00 2026-05-28T20:36:39+00:00

I am trying to Impersonate different users in order to find differences between two

  • 0

I am trying to Impersonate different users in order to find differences between two directories. This is my Code, but i get Access denied when the query executes. Notice that the users are correct and the above impersonation works when both DirectoryInfo executes.

  Dim impersonateUser As New UserImpersonation
            impersonateUser.impersonateUser("user1", "", "password1")
            Dim dir1 = New DirectoryInfo("\\10.11.11.122\OnDemand Recordings")
            impersonateUser.undoimpersonateUser()

            impersonateUser.impersonateUser("user2", "", "password2")
            Dim dir2 = New DirectoryInfo("\\10.11.11.172\OCDialer_Recordings\OnDemand")
            impersonateUser.undoimpersonateUser()

'In this Block i get access denied
            Dim filesinboth = From f1 In dir1.EnumerateFiles(System.IO.SearchOption.AllDirectories)
                  Join f2 In dir2.EnumerateFiles(System.IO.SearchOption.AllDirectories) On f1.Name Equals f2.Name
                  Select f1.Name
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:36:41+00:00Added an answer on May 28, 2026 at 8:36 pm

    That impersonation probably sets credentials for the current thread, and that’s why you get the access-denied error – as the 2nd impersonation overwrites the 1st (and you can’t have more than one user running a single thread/app at the same time).

    Try this:

    This will work only if you are comparing relatively small amount of information about each file/dir (e.g. their names). Read [full] paths to directories and files into a list or some sort of tree-like/recursive collection (you can create something like the class below for the latter).

    class dir
    {
        public string name { get; set; }
        public List<dir> dirs { get; set; }
        public string files { get; set; }
    }
    

    Or simply store full paths to List<string> (same case for easier comparison).

    Then, read the complete directories separately. Compare them later. Store differences in 3rd list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to get my css / C# functions to look like this: body {
Trying to do this sort of thing... WHERE username LIKE '%$str%' ...but using bound
I am trying to execute a batch file using the Process class. This code
I am writing some code to access directories and index the files it finds.
Trying to launch and pass tel. no. to skype by this code from my
I am trying to get my IIS 7.5 to impersonate the account of the
I'm trying to create a website in IIS using this code (from another site
Trying to find some simple SQL Server PIVOT examples. Most of the examples that
Trying to keep all the presentation stuff in the xhtml on this project and
Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.