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

  • SEARCH
  • Home
  • 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 705249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:01:56+00:00 2026-05-14T04:01:56+00:00

This .NET API works OK if I’m trying to open the Registry in a

  • 0

This .NET API works OK if I’m trying to open the Registry in a machine that’s in the same domain as I am (and my logged-on user has admin rights on the target machine).

It gets tricky if it’s an out-of-domain machine with a different, local administrative user (of whom I do have the password).

I tried to use WNetUseConnection() (which has served me well in the past in situations where what I wanted was to read a remote disk file) prior to calling OpenRemoteBaseKey(), but no dice — I get an access denied exception.

Clearly, I must pass credentials some other way, but how?

  • 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-14T04:01:57+00:00Added an answer on May 14, 2026 at 4:01 am

    What I’ve used successfully to access files on a computer is the following code:

        #region imports 
            [DllImport("advapi32.dll", SetLastError = true)] 
            private static extern bool LogonUser(string 
            lpszUsername, string lpszDomain, string lpszPassword, 
            int dwLogonType, int dwLogonProvider, ref 
    IntPtr phToken); 
    
    
            [DllImport("kernel32.dll", CharSet = CharSet.Auto, 
            SetLastError = true)] 
            private static extern bool CloseHandle(IntPtr handle 
            ); 
    
            [DllImport("advapi32.dll", CharSet = CharSet.Auto, 
            SetLastError = true)] 
            public extern static bool DuplicateToken(IntPtr 
            existingTokenHandle, 
            int SECURITY_IMPERSONATION_LEVEL, ref IntPtr 
            duplicateTokenHandle); 
            #endregion 
            #region logon consts 
            // logon types 
            const int LOGON32_LOGON_INTERACTIVE = 2; 
            const int LOGON32_LOGON_NETWORK = 3; 
            const int LOGON32_LOGON_NEW_CREDENTIALS = 9; 
    
            // logon providers 
            const int LOGON32_PROVIDER_DEFAULT = 0; 
            const int LOGON32_PROVIDER_WINNT50 = 3; 
            const int LOGON32_PROVIDER_WINNT40 = 2; 
            const int LOGON32_PROVIDER_WINNT35 = 1; 
            #endregion 
    

    And then for signing in part, just use:

            IntPtr token = IntPtr.Zero; 
    
            bool isSuccess = LogonUser("username", "domain", "password", 
            LOGON32_LOGON_NEW_CREDENTIALS, 
            LOGON32_PROVIDER_DEFAULT, ref token); 
            using (WindowsImpersonationContext person = new WindowsIdentity(token).Impersonate()) 
            { 
            //do your thing 
             person.Undo(); 
            } 
    

    As you might see, “Undo()” will make that you are no longer signed in as that user. So don’t use it before you’re done. But don’t forget to use it!

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

Sidebar

Related Questions

We have an ASP.NET Web API app which uses Ninject for DI. This works
I'm trying to implement this web api autocomplete in a standard mvc app. http://techbrij.com/987/jquery-ui-autocomplete-asp-net-web-api
This applies to ASP.NET in general but also Web API. How can we handle
In ASP.net MVC4 there's this 'new' concept of a web API for exposing CRUD
This is .NET 4.0/C#. I have a class that inherits from an interface: public
This question is similar to this: Asp.net Profile Across Sub-Domain I'm basically wondering if
In this asp.net page, there is a link that leads to another page in
I am trying to get the current's user last logon. I might be this
I am following this tutorial to build my first Asp.net Web API in a
I'm having a situation that is getting kind of annoying with asp.net web api.

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.