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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:33:13+00:00 2026-05-24T02:33:13+00:00

i have searched and read about issues with psexec.exe from sysinternals not working properly

  • 0

i have searched and read about issues with psexec.exe from sysinternals not working properly with c# and stdout. i am now trying to figure out how to just call a batch file that has the following instead of using System.Diagnostics.Process to call psexec:

test.bat contains the following line:

psexec.exe \\hostname -u user -p password ipconfig /all >c:\test.txt

test.txt will be saved on the host where i am running my c sharp app and executing psexec.

when i execute the following:

System.Diagnostics.Process psexec_run = new System.Diagnostics.Process();
psexec_run.StartInfo.FileName = "cmd.exe";
psexec_run.StartInfo.Arguments = @"/c """ + cur_dir + @"\test\test.bat""";
psexec_run.StartInfo.UseShellExecute = false;
psexec_run.Start();
psexec_run.WaitForExit();

i see the cmd window pop up and it runs something but not sure what and goes away.

if i execute the following:

System.Diagnostics.Process psexec_run = new System.Diagnostics.Process();
psexec_run.StartInfo.FileName = cur_dir + "\\test\\psexec.exe";
psexec_run.StartInfo.Arguments = @"\\hostname -u user -p password ipconfig /all";
psexec_run.StartInfo.UseShellExecute = false;
psexec_run.Start();
psexec_run.WaitForExit();

then i see the command window open and it runs psexec which takes quite a few secs and i quickly see my output i need, but i have no way of capturing the output or writing it to a file.

i guess my issue now is since psexec will not work with stdout how can i capture the output from the psexec command to write it to a file???

see the following link for the issues with psexec, the last reply on this url mentioned a way to write the process output to a file without using stdout, i’m newbie to c# i can’t figure out how to write process output without use stdout 🙁

http://forum.sysinternals.com/psexec-fails-to-capture-stdout-when-launched-in-c_topic19333.html

based on response below i tried the following:

ProcessStartInfo psi = new ProcessStartInfo(cur_dir + "\\test\\psexec.exe",    @"\\hostname -u user -p password ipconfig /all");                   
psi.RedirectStandardOutput = true;         
psi.RedirectStandardError = true;         
psi.UseShellExecute = false;          
Process p = Process.Start(psi);          
StreamReader myStreamReader = p.StandardOutput;          
// Read the standard output of the spawned process.                         
string sOutput = myStreamReader.ReadToEnd(); 

i did ReadToEnd so i would make sure it got all the output, it DID NOT!! for some reason it only go the first line of ipconfig output that was it. Also the cmd window it opened up never closed for some reason. even with CreateNoWindow=true the code just hangs. so again something is wrong with psexec and stdout i think?? as i can run this code just fine using ipconfig /all command on the local host and not use psexec…

again i am looking to avoid stdout and somehow find a way to get the output from this command or unless there is something else i’m over looking? also, not to make more work for anyone, but if you d/l psexec.exe from sysinternals and test it with a command on a remote host you will see. i have spent 2 days on this one 🙁 trying to figure out how to use psexec or find some other quick method to execute remote command on a host and get ouptput.

UPDATE:

i gave up on psexec in c# code, i saw many posts about psexec eating the output, having a child window process ,etcc
until my head hurt 🙂 so i am trying to run a batch file and output to a file and it’s not making sense…

i have a batch file test.bat with the following

psexec.exe \\\hostname -u name -p password ipconfig /all >c:\test.txt

when i run the following code:

ProcessStartInfo psi = new ProcessStartInfo(cur_dir + @"\test\test.bat");

psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.UseShellExecute = false;
Process p = Process.Start(psi);

p.WaitForExit();

the cmd windows comes and goes really quickly and the test.txt file is created but is 0 bytes no info in it.

so if i run the batch file in a windows cmd line with the psexec command it works perfectly fine!!???

so then to verify psexec was the issue i changed the batch file to:

ipconfig /all >c:\test.txt

i execute my code above and it works fine creates the output in the test.txt file..???!!!!

why is not working with psexec am i missing something? if it’s psexec, does anyone have
any recommendations for how i can execute a command on a remote windows host and get me the
output???

  • 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-24T02:33:14+00:00Added an answer on May 24, 2026 at 2:33 am

    i found a solution. apparently psexec is NOT going to work in c sharp. so i came up with some wmi code to connect to a remote host and it’s working PERFECTLY!!! 🙂

    i used microsoft’s WMICodeCreator.exe to create wmi code for C# for the process method on a remote host, wow that tool is amazing because wmi code is little confusing to me.

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

Sidebar

Related Questions

I've searched for this a little but I have not gotten a particularly straight
I have searched various online resources and found conflicting information about the possibility of
i have searched google, tried to read adhearsion docs and make sense of the
I've read through the docs and searched on here, but I'm not quite understanding
I have been working with managing agile teams for quite some time. Now I'm
i have searched a lot but could not find the exact way to do
I have been working on this for a few days now and I have
I have searched around, and it seems that this is a limitation in MS
I have searched but apparently my google foo is weak. What I need is
I've have searched on this and it seems to be a catch all, unfortunately

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.