Why so few options for ProcessWindowStyle enumeration?

  • Thread starter Thread starter Chuck Heatherly
  • Start date Start date
C

Chuck Heatherly

There are times when I want to start a child process from my main process, and
show the user that it is running, but have the active window focus remain on my
main process. From what I can tell, this is only possible in managed .NET by
using the Visual Basic .NET function Shell(), parameter 2 which is of type
AppWinStyle. This enumeration contains the value "MinimizedNoFocus", which does
exactly what I want.

My question is, why does the ProcessWindowStyle enumeration in the main .NET
Framework not provide this window style? I would prefer to use the Process and
ProcessStartInfo classes to start child processes because they offer so many
more options for control. But the ProcessWindowStyle enumeration only has
values for "Hidden", "Maximized", "Minimized", and "Normal". When I use
"Minimized", the new child process steals the active window focus, which is a
big problem for my application.

Is there any other way to set this window style while using the
System.Diagnostics classes?

I checked the February 2005 CTP of Visual Studio 2005, there have been no new
values added to the ProcessWindowStyle enumeration.

Thanks for any help,
Chuck
 
Hi

I think so far we can workaround the problem by using the VisualBasic class
in C#.
Add a reference to microsoft.visualbasic.dll
Run the code below to use the vb shell syntax in C#.
private void button1_Click(object sender, System.EventArgs e)
{

Microsoft.VisualBasic.Interaction.Shell(@"Notepad.exe",Microsoft.VisualBasic
..AppWinStyle.NormalNoFocus,false,-1);
}

You may also try to submit your feedback to mswish website and our
dedicated team will evaluate the request.
http://register.microsoft.com/mswish/suggestion.asp


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi

I think so far we can workaround the problem by using the VisualBasic class
in C#.
Add a reference to microsoft.visualbasic.dll
Run the code below to use the vb shell syntax in C#.
private void button1_Click(object sender, System.EventArgs e)
{

Microsoft.VisualBasic.Interaction.Shell(@"Notepad.exe",Microsoft.VisualBasic
AppWinStyle.NormalNoFocus,false,-1);
}

Peter, I appreciate your followup, but this workaround only solves the problem
in a few cases, where the only things I need to specify for the process are the
path name, window style, whether the method should wait for completion of the
process, and a timeout if the wait does occur. If I need to specify other
properties of the process, such as the many items in the
System.Diagnostics.ProcessStartInfo class, then what do I do? For example, if I
want the child process to be minimized with no focus, and I also want to
redirect standard error and set the working directory, how do I do that in a
managed way?

To me, it seems like the VB team and the framework team wrote completely
separate managed versions of the Win32 CreateProcess API, and both versions have
different feature sets. The only answer I can come up with for an example like
the one I described above, is for me to write my own managed version of
CreateProcess that includes everything, and that just seems completely backwards
to me. I don't have a problem using P/Invoke some of the time, but I thought
that .NET was supposed to be a step forward away from having to use API calls
all the time.
You may also try to submit your feedback to mswish website and our
dedicated team will evaluate the request.
http://register.microsoft.com/mswish/suggestion.asp

Thanks for the link, I will definitely do this.

Sorry if this reply comes across as a lot of whining, but it is just frustrating
to me to find a class as detailed as ProcessStartInfo but then find that it is
not complete, and that there is no managed way to accomplish everything I need,
and the solution of me rewriting a wrapper for CreateProcess being very
time-intensive, and completely unnecessary in this case (i.e., writing my own
P/Invoke calls is fine when there is no direct managed equivalent, but having to
write a wrapper because the official wrappers are incomplete, that's just
ridiculous. CreateProcess is Microsoft's own API in the first place, when they
wrote a managed wrapper for it, it should have been obvious just from reading
the MSDN doc what parameters and values needed to be supported).

Again, my frustrations are not directed at you Peter, I appreciate your getting
back to me. I'm just frustrated with the lack of communication that apparently
occurred between the VB and Framework teams in this case. And I realize that
such communication problems happen in every company, even more so in huge ones
like Microsoft.

Chuck
 
Hi

Thanks for your feedback.
Based on research, the Shell method will call the CreateProcess directly
underlying, while the Process class goes the .NET framework way to call the
CreateProcess. Because the visualbasic namespace is for the migration of
the VB6 user which is not the common language runtime do.

So far the Process class did not wrap the whole functions of the
CreateProcess api, and we will keep improving our product. If the shell
method did not fit you, I think we had to call the CreateProcess API
directly in C#.

If you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top