Hiding the Process Window when running as a different user

H

Huey

I need to hide the new window started from the code below. If I run as is,
the window is visible. If I comment out the code that sets a different user,
domain, and password the window is hidden as desired. Does anyone know if
there is a known issue with hiding a process window when you run it as a
different user? Do you have any suggestions to work around this problem?
Thank you.

Process proc = new Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.Arguments = "/C time /T";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.Domain = CurrentAdmin.Domain;
proc.StartInfo.UserName = CurrentAdmin.UserID;
proc.StartInfo.Password = CurrentAdmin.Password;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.Start();
StreamReader myOutput = proc.StandardOutput;

proc.WaitForExit();

while (myOutput.EndOfStream == false)
{
string Inline;
Inline = myOutput.ReadLine();
Response = Response + Inline + Environment.NewLine;
}
MessageBox.Show(Response);
 
H

Huey

Bumping this one once. I really would like to get a professional opinion on
how to do this, please.
 
A

Andrew

Quote from MSDN for the Process.StartInfo Property:

"If you call the Start(ProcessStartInfo) method with the
ProcessStartInfo..::.UserName and ProcessStartInfo..::.Password properties
set, the unmanaged CreateProcessWithLogonW function is called, which starts
the process in a new window even if the CreateNoWindow property value is
true or the WindowStyle property value is Hidden."
 
H

Huey

Thanks! I feel sufficiently stupid now. :]

Andrew said:
Quote from MSDN for the Process.StartInfo Property:

"If you call the Start(ProcessStartInfo) method with the
ProcessStartInfo..::.UserName and ProcessStartInfo..::.Password properties
set, the unmanaged CreateProcessWithLogonW function is called, which starts
the process in a new window even if the CreateNoWindow property value is
true or the WindowStyle property value is Hidden."
 
A

Andrew

No need to, I am glad I could help you.
Sometimes MSDN does it's job well :)
I thought it will say about this in the description of either the method or
structures used in the method.

Huey said:
Thanks! I feel sufficiently stupid now. :]

Andrew said:
Quote from MSDN for the Process.StartInfo Property:

"If you call the Start(ProcessStartInfo) method with the
ProcessStartInfo..::.UserName and ProcessStartInfo..::.Password
properties
set, the unmanaged CreateProcessWithLogonW function is called, which
starts
the process in a new window even if the CreateNoWindow property value is
true or the WindowStyle property value is Hidden."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top