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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:16:28+00:00 2026-05-30T12:16:28+00:00

I am trying to execute a batch file using the Process class. This code

  • 0

I am trying to execute a batch file using the Process class. This code is in the middle of a larger section of code where I am using LogonUser() and WindowsIdentity.Impersonate() to impersonate the local PC admin account.

I was attempting to run a batch file within a Process, without adding credentials in ProcessStartInfo, but doing it that way caused the batch file to fail silently – no errors were raised, and expected output from the batch file never was returned (I am reading stderr and stdout asynchronously, fwiw).

I then added the credentials to ProcessStartInfo, but now I get an “Access is denied” error if I do not first call WindowsImpersonationContext.Undo(), and an “Logon failure: unknown username or bad password” error if I do call .Undo() before Process.Start(). I have triple-checked that the username/password/domain is correct, for multiple accounts.

If my code has no LogonUser() or WindowsIdentity.Impersonate() calls (and no credentials in ProcessStartInfo), then I don’t have a problem with the batch file executing and output from batch file being captured.

I am able to run the batch file from the desktop successfully, either as the local admin or an arbitrary local user account. I can see its permissions show that it should be readable/executable from the accounts I am trying to run it. This is really quite the stumper; any help is appreciated.

  • 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-30T12:16:29+00:00Added an answer on May 30, 2026 at 12:16 pm

    The problem was that I needed to redirect all 3 streams; I was only redirecting 2 (out, err, not in). That basically fixed things.

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

Sidebar

Related Questions

I am trying to execute a batch file from C# code using Process class.
I'm trying to execute a simple batch file from java using Runtime.getRuntime().exec(command); but facing
I'm trying to execute this: $ mysql --user=XXX --password=XXX --batch --skip-column-names \ -e SELECT
I am trying to execute this SQL query prior to restoring a .BAK file
I'm trying to execute class file. After that I need the output of the
I'm trying to execute a 3rd party application, called from a .cmd batch file,
I am trying to write a batch file to iteratively execute a fortran compiled
I'm trying to execute a batch file in C#, but I'm not getting any
I'm trying to create batch file which should have this commands: cd c:\Program files\NuSMV\2.5.2\bin\
I'm trying to install a Windows Service using a batch file, let's call it

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.