询问者
关于coredll.dll中CreateProcess方法里的一个参数如何输入问题

问题
-
[DllImport("coredll.dll", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Auto)] static extern bool CreateProcess( string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, IntPtr lpStartupInfo, out ProcessInfo lpProcessInformation );
private void button1_Click(object sender, EventArgs e)
{
ProcessInfo pi; // no new required since ProcessInfo is a value type (struct)
CreateProcess(
"cmd.exe",
@"/c start wzctool.exe -e >acc.txt",
IntPtr.Zero,
IntPtr.Zero,
false,
0,
IntPtr.Zero,
null,
IntPtr.Zero,
out pi
);}
当我这个参数输入为0时候,cmd窗口会闪一下,然后我改成了1,按下按钮后,界面无反应,txt文件也未生产,不过一关闭winform程序后,cmd窗口会闪一下txt文档也生成了,
查了下msdn(http://msdn.microsoft.com/zh-cn/library/ms684863)
- CREATE_NO_WINDOW 0x08000000
-
The process is a console application that is being run without a console window. Therefore, the console handle for the application is not set.
This flag is ignored if the application is not a console application, or if it is used with either CREATE_NEW_CONSOLE or DETACHED_PROCESS.
-
这个参数原来的类型是DWORD dwCreationFlags 我查了下资料,DWORD在C#里面可以用uint代替,这个东西是2个双字节东西。。。
-
0x08000000是一个十六进制数。。。。
-
我编程基础不是很好。。。这里我不知该如何输入这个参数,才能到达CREATE_NO_WINDOW效果。。。。。
-
我该如何是好啊。。。。
- 已移动 Leo Liu - MSFT 2011年2月15日 2:43 Off-topic, moved for better support. (发件人:Visual C#)
全部回复
-
你好!
可以直接用 .net 中 System.Diagnostics.Process 类达到上述效果,如下:
ProcessStartInfo p = new ProcessStartInfo(); p.FileName = "cmd.exe"; p.UseShellExecute = true; p.Arguments = "/k dir"; p.CreateNoWindow = true; p.WindowStyle = ProcessWindowStyle.Hidden; // 隐藏窗体 Process.Start(p); Console.ReadLine();
知识改变命运,奋斗成就人生! -
谢谢大家的热心,上述的方法我是知道的,那些在windows xp下可以使用。。。
是我问题没有提清楚,我做的程序在wince系统下的。。。
.net cf 里面的Process类没有隐藏窗口的属性或方法。。。。
我查了好多资料,好多都是vc++的就是通过CreateProcess实现的。。。
我问题中的代码是我找到的C#版本的。。可是他没提供隐藏窗口的例子。。。
查了下msdn(http://msdn.microsoft.com/zh-cn/library/ms684863),里面提到的
“
- CREATE_NO_WINDOW 0x08000000
The process is a console application that is being run without a console window. Therefore, the console handle for the application is not set.
This flag is ignored if the application is not a console application, or if it is used with either CREATE_NEW_CONSOLE or DETACHED_PROCESS.
”
但是不知该如何输入uint dwCreationFlags这个参数,所以在此请教下应该如何输入这个参数。。。
-
Hi 张诚亮,
欢迎来到MSDN论坛。
我现在将您的帖子移到Windows Embedded CE Forum以便得到更好的支持。
谢谢您的理解。
Sincerely,
Leo Liu
Leo Liu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.