Process.Start和控制台窗口问题 [英] Process.Start and Console Window Issue

查看:51
本文介绍了Process.Start和控制台窗口问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用System.Diagnostics.Process.Start方法启动常见的

或花园控制台应用程序时,可以设置

StartInfo对象的WindowStyle属性到ProcessWindowStyle.Hidden,以便

控制台应用程序的窗口不可见。


但是,当使用某些''高级''属性时StartInfo

对象,如用户名,密码和域,将忽略

StartInfo对象的WindowsStyle属性。 (这是因为Process.Start方法调用了对于ShellExecuteEx的'正常''

调用CreateProcess(或其中一个变种)的内部调用
a 。)


不幸的是,这导致控制台应用程序窗口显示

看起来很难看。


效果通过在控制台应用程序的生命周期中调用

调用应用程序TopMost的窗口可以稍微减轻这一点,至少
使得控制台成为控制台应用程序窗口出现在

窗口后面的调用应用程序。


有没有遇到过这个''问题'的人设法找到一种方法''在这种情况下隐藏''

控制台应用程序窗口?

When one uses the System.Diagnostics.Process.Start method to launch a common
or garden Console application, one can set the WindowStyle property of the
StartInfo object to ProcessWindowStyle.Hidden so that the window for the
Console application is not visible.

However, when using some of the ''advanced'' properties of the StartInfo
object, like Username, Password and Domain, the WindowsStyle property of the
StartInfo object is ignored. (This is because the Process.Start method makes
a call to CreateProcess (or one of it''s variants) intead of the ''normal''
call to ShellExecuteEx.)

Unfortunately this results in the Console application window being shown
which looks ugly.

The effect of this can be somewhat mitigated by making the window of the
calling application ''TopMost'' for the life of the Console application which,
at least, makes the Console application window appear behind the window of
the calling application.

Has anyone who has encountered this ''issue'' managed to find a way to ''hide''
the Console application window under this scenario?

推荐答案

3月13日,5日:下午36点,Stephany Young < noone @ localhostwrote:
On Mar 13, 5:36 pm, "Stephany Young" <noone@localhostwrote:

当使用System.Diagnostics.Process.Start方法启动常见的

或花园控制台应用程序时,可以将

StartInfo对象的WindowStyle属性设置为ProcessWindowStyle.Hidden,以便不显示

控制台应用程序的窗口。

但是,当使用StartInfo

对象的某些''高级''属性时,如Username,Password和Domain,
$ b $的WindowsStyle属性b忽略StartInfo对象。 (这是因为Process.Start方法调用了对于ShellExecuteEx的'正常''

调用CreateProcess(或其中一个变种)的内部调用
a 。)


不幸的是,这导致控制台应用程序窗口显示

看起来很难看。


效果通过在控制台应用程序的生命周期中调用

调用应用程序TopMost的窗口可以稍微减轻这一点,至少
使得控制台成为控制台应用程序窗口出现在

窗口后面的调用应用程序。


有没有遇到过这个''问题'的人设法找到一种方法''在这种情况下隐藏''

控制台应用程序窗口?
When one uses the System.Diagnostics.Process.Start method to launch a common
or garden Console application, one can set the WindowStyle property of the
StartInfo object to ProcessWindowStyle.Hidden so that the window for the
Console application is not visible.

However, when using some of the ''advanced'' properties of the StartInfo
object, like Username, Password and Domain, the WindowsStyle property of the
StartInfo object is ignored. (This is because the Process.Start method makes
a call to CreateProcess (or one of it''s variants) intead of the ''normal''
call to ShellExecuteEx.)

Unfortunately this results in the Console application window being shown
which looks ugly.

The effect of this can be somewhat mitigated by making the window of the
calling application ''TopMost'' for the life of the Console application which,
at least, makes the Console application window appear behind the window of
the calling application.

Has anyone who has encountered this ''issue'' managed to find a way to ''hide''
the Console application window under this scenario?



这可能并不完美,但凭借你的能力,你应该能够根据你的需要调整它。


这是一个表单的代码,其中一个按钮名为Button1 - 它使用了

FindWindow和ShowWindow API:


公共类Form1


私有子Form1_Load(ByVal发送者为对象,ByVal e As

System.EventArgs)处理Me.Load

Process.Start(" C:\ ControlApplication1.exe")

End Sub


< System.Runtime.InteropServices.DllImport(" ; user32")_

Public Shared Sub ShowWindow(ByVal hWnd As IntPtr,ByVal nCmdShow

As Int32)

End Sub


< System.Runtime.InteropServices.DllImport(" user32")_

公共共享函数FindWindow(ByVal lpClassName As String,

ByVal lpWindowname As String)作为IntPtr

结束功能


Private Sub Bu tton1_Click(ByVal sender As System.Object,ByVal e

As System.EventArgs)处理Button1.Click

Dim hWnd As IntPtr = FindWindow(Nothing,C:

\ConsoleApplication1.exe")

ShowWindow(hWnd,0)

结束子


结束课


我希望这会帮助你!


谢谢,


Seth Rowe


This probably isn''t perfect, but with your abilities you should be
able to adapt it to fit your needs.

This is the code for a form with one button named Button1 - it uses
the FindWindow and ShowWindow APIs:

Public Class Form1

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Process.Start("C:\ConsoleApplication1.exe")
End Sub

<System.Runtime.InteropServices.DllImport("user32" )_
Public Shared Sub ShowWindow(ByVal hWnd As IntPtr, ByVal nCmdShow
As Int32)
End Sub

<System.Runtime.InteropServices.DllImport("user32" )_
Public Shared Function FindWindow(ByVal lpClassName As String,
ByVal lpWindowname As String) As IntPtr
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim hWnd As IntPtr = FindWindow(Nothing, "C:
\ConsoleApplication1.exe")
ShowWindow(hWnd, 0)
End Sub

End Class

I hope this helps you out!

Thanks,

Seth Rowe


感谢Seth。


控制台应用程序问题是一个短暂的,需要

命令行参数并且不做''交互式输入/输出。


调用ShowWindow失败,因为控制台应用程序窗口已经

并且在调用应用程序中的代码可以处理它之前消失了。


这是控制台应用程序窗口出现和消失使得

看起来很难看。

" rowe_newsgroups" < ro ******** @ yahoo.com在留言中写道

新闻:11 ********************** @ n76g2000hsh.googlegr oups.com ...
Thanks for that Seth.

The console application is question is one that is short lived, takes
command line arguments and doesn''t ''do'' interactive input/output.

A call to ShowWindow fails because the console application window has been
and gone before the code in the calling application can deal with it.

It is the console application window appearing and disappearing that makes
it look ugly.
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@n76g2000hsh.googlegr oups.com...

3月13日下午5:36,Stephany Young < noone @ localhostwrote:
On Mar 13, 5:36 pm, "Stephany Young" <noone@localhostwrote:

>当使用System.Diagnostics.Process.Start方法启动
常用
或花园时控制台应用程序,可以将
StartInfo对象的WindowStyle属性设置为ProcessWindowStyle.Hidden,以便
控制台应用程序的窗口不可见。

然而,当使用StartInfo
对象的某些高级属性(如用户名,密码和域)时,将忽略
StartInfo对象的WindowsStyle属性。 (这是因为Process.Start方法
调用CreateProcess(或其中一个变种)对'正常''
调用ShellExecuteEx的内容。)<不幸的是,这导致控制台应用程序窗口显示
看起来很难看。

通过制作
在控制台应用程序的生命周期中调用应用程序''TopMost'
,至少使控制台应用程序窗口显示在调用应用程序的窗口后面。

有没有遇到过这个问题的人设法在这种情况下找到一种方法来隐藏''控制台应用程序窗口?
>When one uses the System.Diagnostics.Process.Start method to launch a
common
or garden Console application, one can set the WindowStyle property of
the
StartInfo object to ProcessWindowStyle.Hidden so that the window for the
Console application is not visible.

However, when using some of the ''advanced'' properties of the StartInfo
object, like Username, Password and Domain, the WindowsStyle property of
the
StartInfo object is ignored. (This is because the Process.Start method
makes
a call to CreateProcess (or one of it''s variants) intead of the ''normal''
call to ShellExecuteEx.)

Unfortunately this results in the Console application window being shown
which looks ugly.

The effect of this can be somewhat mitigated by making the window of the
calling application ''TopMost'' for the life of the Console application
which,
at least, makes the Console application window appear behind the window
of
the calling application.

Has anyone who has encountered this ''issue'' managed to find a way to
''hide''
the Console application window under this scenario?




这可能并不完美,但是你的能力应该是

能够适应你的需要需要。


这是一个表单的代码,其中一个按钮名为Button1 - 它使用了

FindWindow和ShowWindow API:

Public Class Form1


Private Sub Form1_Load(ByVal sender As Object,ByVal e As

System.EventArgs)处理Me.Load

Process.Start(" C:\ ControlPalication1.exe")

End Sub


< System.Runtime.InteropServices .DllImport(" user32")_

Public Shared Sub ShowWindow(ByVal hWnd As IntPtr,ByVal nCmdShow

As Int32)

End Sub


< System.Runtime.InteropServices.DllImport(" user32")_

公共共享函数FindWindow(ByVal lpClassName As String,

ByVal lpWindowname As String)作为IntPtr

结束函数


Private Sub Button1_Click(ByVal sender As System.Object,ByVal e

As System.EventArgs)处理Button1.Click

Dim hWnd As IntPtr = FindWindow(Nothing,C:

\ConsoleApplication1.exe)

ShowWindow(hWnd,0)

结束子


结束课


我希望这能帮到你!


谢谢,


Seth Rowe



This probably isn''t perfect, but with your abilities you should be
able to adapt it to fit your needs.

This is the code for a form with one button named Button1 - it uses
the FindWindow and ShowWindow APIs:

Public Class Form1

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Process.Start("C:\ConsoleApplication1.exe")
End Sub

<System.Runtime.InteropServices.DllImport("user32" )_
Public Shared Sub ShowWindow(ByVal hWnd As IntPtr, ByVal nCmdShow
As Int32)
End Sub

<System.Runtime.InteropServices.DllImport("user32" )_
Public Shared Function FindWindow(ByVal lpClassName As String,
ByVal lpWindowname As String) As IntPtr
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim hWnd As IntPtr = FindWindow(Nothing, "C:
\ConsoleApplication1.exe")
ShowWindow(hWnd, 0)
End Sub

End Class

I hope this helps you out!

Thanks,

Seth Rowe


3月13日晚上8:35,Stephany Young < noone @ localhostwrote:
On Mar 13, 8:35 pm, "Stephany Young" <noone@localhostwrote:

感谢Seth。


控制台应用程序问题是短暂的问题,接受

命令行参数并且不做'交互式输入/输出。


由于控制台应用程序窗口,对ShowWindow的调用失败在调用应用程序中的代码可以处理它之前已经消失了。


控制台应用程序窗口出现并消失使得

看起来很难看。


" rowe_newsgroups" < rowe_em ... @ yahoo.com写了留言


新闻:11 ********************** @ n76g2000hsh.googlegr oups.com ...
Thanks for that Seth.

The console application is question is one that is short lived, takes
command line arguments and doesn''t ''do'' interactive input/output.

A call to ShowWindow fails because the console application window has been
and gone before the code in the calling application can deal with it.

It is the console application window appearing and disappearing that makes
it look ugly.

"rowe_newsgroups" <rowe_em...@yahoo.comwrote in message

news:11**********************@n76g2000hsh.googlegr oups.com...

3月13日下午5:36,Stephany Young < noone @ localhostwrote:
On Mar 13, 5:36 pm, "Stephany Young" <noone@localhostwrote:

当使用System.Diagnostics.Process.Start方法启动



或花园控制台应用程序,可以将

的WindowStyle属性设置为/ b $ B $ StartInfo对象到ProcessWindowStyle.Hidden以便窗口为

控制台应用程序不可见。
When one uses the System.Diagnostics.Process.Start method to launch a
common
or garden Console application, one can set the WindowStyle property of
the
StartInfo object to ProcessWindowStyle.Hidden so that the window for the
Console application is not visible.


但是,当使用StartInfo的某些高级属性时/>
对象,如用户名,密码和域,

的WindowsStyle属性

StartInfo对象被忽略。 (这是因为Process.Start方法

调用CreateProcess(或其中一个变体)调用''normal''

调用ShellExecuteEx。)
However, when using some of the ''advanced'' properties of the StartInfo
object, like Username, Password and Domain, the WindowsStyle property of
the
StartInfo object is ignored. (This is because the Process.Start method
makes
a call to CreateProcess (or one of it''s variants) intead of the ''normal''
call to ShellExecuteEx.)


不幸的是,这导致了Console应用程序窗口被显示

看起来很难看。
Unfortunately this results in the Console application window being shown
which looks ugly.


通过制作
窗口,可以在一定程度上减轻这种影响
在控制台应用程序的生命周期中调用应用程序''TopMost'

,至少
,使控制台应用程序窗口出现在窗口后面



调用应用程序。
The effect of this can be somewhat mitigated by making the window of the
calling application ''TopMost'' for the life of the Console application
which,
at least, makes the Console application window appear behind the window
of
the calling application.


有没有遇到这个''问题'的人设法找到了一条路

''隐藏''

此方案下的控制台应用程序窗口?
Has anyone who has encountered this ''issue'' managed to find a way to
''hide''
the Console application window under this scenario?


这可能并不完美,但凭借你的能力,你应该是

能够适应它符合您的需求。
This probably isn''t perfect, but with your abilities you should be
able to adapt it to fit your needs.


这是一个表单的代码,其中一个按钮名为Button1 - 它使用了

FindWindow和ShowWindow API:
This is the code for a form with one button named Button1 - it uses
the FindWindow and ShowWindow APIs:


Public Class Form1
Public Class Form1


Private Sub Form1_Load(ByVal sender As Object ,ByVal e As

System.EventArgs)处理Me.Load

Process.Start(" C:\ ControlApplication1.exe")

End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Process.Start("C:\ConsoleApplication1.exe")
End Sub


< System.Runtime.InteropServices.DllImport(" user32")_

Public Shared Sub ShowWindow(ByVal hWnd As IntPtr,ByVal nCmdShow

As Int32)

End Sub
<System.Runtime.InteropServices.DllImport("user32" )_
Public Shared Sub ShowWindow(ByVal hWnd As IntPtr, ByVal nCmdShow
As Int32)
End Sub


< System.Runtime.InteropServices.DllImport(" user32")_

公共共享函数FindWindow(ByVal lpClassName As Stri ng,

ByVal lpWindowname As String)As IntPtr

结束函数
<System.Runtime.InteropServices.DllImport("user32" )_
Public Shared Function FindWindow(ByVal lpClassName As String,
ByVal lpWindowname As String) As IntPtr
End Function


Private Sub Button1_Click (ByVal sender As System.Object,ByVal e

As System.EventArgs)处理Button1.Click

Dim hWnd As IntPtr = FindWindow(Nothing,C:

\ConsoleApplication1.exe")

ShowWindow(hWnd,0)

End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim hWnd As IntPtr = FindWindow(Nothing, "C:
\ConsoleApplication1.exe")
ShowWindow(hWnd, 0)
End Sub


结束类
End Class


我希望这可以帮到你!
I hope this helps you out!


谢谢,
Thanks,


Seth Rowe
Seth Rowe



对不起,它没有用。


你可以重写控制台应用程序还是隐藏代码有

在调用程序中吗?


谢谢,


Seth Rowe

Sorry it didn''t help.

Can you rewrite the console application or does the "hide" code have
to be in the calling program?

Thanks,

Seth Rowe


这篇关于Process.Start和控制台窗口问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆