c# calling process "cannot find the file specified"
Posted
by laura
on Stack Overflow
See other posts from Stack Overflow
or by laura
Published on 2010-05-25T16:33:25Z
Indexed on
2010/05/25
16:41 UTC
Read the original article
Hit count: 305
c#
I'm a c# newbie so bear with me. I'm trying to call "pslist" from PsTools from a c# app, but I keep getting "The system cannot find the file specified". I thought I read somewhere on google that the exe should be in c:\windows\system32, so I tried that, still nothing. Even trying the full path to c:\windows\system32\PsList.exe is not working. I can open other things like notepad or regedit. Any ideas?
C:\WINDOWS\system32>dir C:\WINDOWS\SYSTEM32\PsList.exe Volume in drive C has no label. Volume Serial Number is ECC0-70AA Directory of C:\WINDOWS\SYSTEM32 04/27/2010 11:04 AM 231,288 PsList.exe 1 File(s) 231,288 bytes 0 Dir(s) 8,425,492,480 bytes free
try
{
// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
//This works
//p.StartInfo.FileName = @"C:\WINDOWS\regedit.EXE";
//This doesn't
p.StartInfo.FileName = @"C:\WINDOWS\system32\PsList.exe";
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
p.WaitForExit();
// Read the output stream first and then wait.
s1 = p.StandardOutput.ReadToEnd();
p.WaitForExit();
}
catch (Exception ex)
{
Console.WriteLine("Exception Occurred :{0},{1}",
ex.Message, ex.StackTrace.ToString());
Console.ReadLine();
}
© Stack Overflow or respective owner