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 6860099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:21:57+00:00 2026-05-27T02:21:57+00:00

Is it possible for a C# Windows service running as Local System or Local

  • 0

Is it possible for a C# Windows service running as Local System or Local Service to impersonate another user without needing a password for that user?

How would this be done?

Note: My motivation for this is to be able to run user specific WMI queries in a service. The WMI calls I’m making (to the OfflineFiles WMI API) are user sensitive, and they only work when I run my service as the user whose data I want to query. I don’t want users to have to enter their usernames and passwords when installing the service, so I’d like to just run the service as Local System or something, and impersonate the user I care about.

  • 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-27T02:21:58+00:00Added an answer on May 27, 2026 at 2:21 am

    Assuming you only need start impersonation whilst the relevant user is logged on, you could:

    1. Locate relevant user session using EnumProcesses (eg http://msdn.microsoft.com/en-us/library/windows/desktop/ms682623(v=vs.85).aspx) [winapi]
    2. OpenProcessToken() on relevant user process [winapi]
    3. DuplicateToken() with impersonation privileges [winapi]
    4. Create a new WindowsIdentity() using the result of DuplicateToken
    5. Call .Impersonate on your new identity from step 4

    Once the token has been duplicated, it doesn’t matter if the user logs of – the impersonation in your service remains.

    Apparently the API the undocumented ZwCreateToken winapi function can achieve this although also, but I have never used it and may break at anytime in future.

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

Sidebar

Related Questions

I have a windows service (currently running under Windows 2003 Server) that needs to
Is it possible to create a C# EXE or Windows Service that can process
I'm building a Windows service that performs different actions based on which Windows user
I have have running windows service that is using it's app.config for getting some
Possible Duplicate: Querying if a Windows Service is disabled (without using the Registry)? I
We have built a Windows Service that is running on client's machines, which occasionally
Is it possible to use an UnhandledException Handler in a Windows Service? Normally I
Is it possible to run a ruby application as a Windows Service? I see
It's possible, but is it appropriate to use SHFileOperation within a Windows service? All
Is it possible to create Windows CE 5.0 images (ie: nk.bin) from VS2005/VS2008 without

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.