473,418 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

Process with Username in 2.0 pops up window even if CreateNoWindow

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]

Nov 17 '05 #1
3 4231


"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.
Nov 17 '05 #2
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.

Nov 17 '05 #3
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.


Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: bamapookie | last post by:
I've written an app that starts and monitors a number of processes. If one of those processes dies, the app restarts it. One of the options I've written hides the main window of the monitored...
0
by: bamapookie | last post by:
I'm sorry if this was posted several times. I did not see my previous post appear after I posted it. I've written an app that starts and monitors a number of processes. If one of those...
11
by: Chippy | last post by:
This is driving me NUTZ. All of my forms are keeping the size of the window I design them in, even when I have the AutoResize option set to Yes. The actual form (grey, gridded area) is the size...
1
by: MS MVP ??? for VB.NET | last post by:
Dear all, I am trying to get the Process UserName by using System.Enviorment.Username, I have no problem by normal "run" and by "runas". I can get the process Username with correct value....
2
by: Zorpiedoman | last post by:
I would like to be able to start a process, but then maintain some control over the window it creates. (Size, position, always on top, etc.) Can't seem to locate documentation on this one. Can...
4
by: drodrig | last post by:
Hi. I am trying to close/kill all processes that show visible windows on Windows XP. So far I've created a script that uses win32gui.EnumWindows to iterate through all windows, check for which...
2
by: tomko | last post by:
Hi, My program uses the Process class to start a bat file that starts an exe. When I run my program inside Visual Studio (debug) the bat and exe run in the background (are not visible) and all...
0
by: smimon | last post by:
Hi I'm trying to run a DTS package from a ASP.NET web page using System.Diagnostics.Process. This DTS takes up to 10 minutes to complete, during which, output is generated which i would like to...
4
by: boudrcj | last post by:
I'm having problems accessing elements of a child window even though both pages are in the same domain. The code works find if the two pages are from the same server, but not when I put them on...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.