William,
What the KB article is talking about is the startinfo.wShowWindow flag or
the .NET equivalent
p.StartInfo.WindowStyle = ProcessWindowStyle.xxxxx;
So you have to set ProcessWindowStyle.Hidden if you want to hide the dos
command window, unfortunately this flag is ignored in Whidbey Beta2.
I tested this with a C++ program that calls CreateProcessWithLogonW API
(this is the API called by .NET when StartInfo.UserName is not empty), and
it works when setting following flags in the STARTUPINFO struct.
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
note that SW_HIDE is ignored (and the window shown) when
STARTF_USESHOWWINDOW is not set, which is the 'documented' behavior (see the
CreateProcessWithLogonW API description).
..NET however fails to set the STARTF_USESHOWWINDOW flag, so it's normal that
ProcessWindowStyle.Hidden is ignored as well.
Now the funny thing is that calling CreateProcess (that is when you don't
specify a StartInfo.UserName)
works as expected while it's using the same STARTUPINFO struct.
So it looks like this is a Beta2 issue, or the documented behavior of
CreateProcessWithLogonW (see STARTF_USESHOWWINDOW) is wrong.
I would suggest you to file a bug.
Willy.
"William Stacey [MVP]" <st***********@mvps.org> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
Thanks Willy. That sounds exactly what the issue is, however I have been
use xp w/ sp2. Maybe you (or others) could try the code on their SP2/fx
2.0 build and see if they see the same thing. Thanks much!
--
William Stacey [MVP]
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:el****************@tk2msftngp13.phx.gbl...
"William Stacey [MVP]" <st***********@mvps.org> wrote in message
news:eq**************@TK2MSFTNGP14.phx.gbl... Is this a bug in fx2? I expect they did not carry forward all the
StartInfo properties to api used with Username/Password. When you
remove UserName/password, the window does not show as expected.
private void button5_Click(object sender, EventArgs e)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = @"/c dir c:\windows\system32";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardInput = true;
// *Note:
// With UserName/Password, Console window shows when should be
hidden.
// Without UserName/Password, Consoel windows is hidden as expected.
p.StartInfo.UserName = "staceyw";
SecureString ss = new SecureString();
string pw = "password"; // Users password.
foreach ( char c in pw )
{
ss.AppendChar(c);
}
p.StartInfo.Password = ss;
p.Start();
StreamReader myStreamReader = p.StandardOutput;
string myString = myStreamReader.ReadToEnd();
Console.WriteLine(myString);
p.Close();
}
--
William Stacey [MVP]
IMO not a bug in fx2, but the result of a CreateProcessWithLogonW bug on
XP pre SP2 and W2K3 pre SP1.
http://support.microsoft.com/?kbid=818858
Willy.