createprocess中的Process.arguments?

Posted

技术标签:

【中文标题】createprocess中的Process.arguments?【英文标题】:Process.arguments in createprocess? 【发布时间】:2013-01-13 22:17:27 【问题描述】:

以下在 process.start 情况下工作得很好。

private string Path()
        
            RegistryKey Key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Wizet\\");
            RegistryKey Location = Key.OpenSubKey("MapleStory");
            return Location.GetValue("ExecPath").ToString();
        

public bool Launch()
        
            maplestory = new ProcessStartInfo();
            maplestory.FileName = Path() + @"\MapleStory.exe";
            maplestory.Arguments = "WebStart";

            MapleStory = Process.Start(maplestory);

如果我要使用 CreateProcess,我现在应该在哪里放置“.Arguments”,以及我应该在哪里放置 CREATE_SUSPENDED?

CreateProcess(AppName, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, false, 0, IntPtr.Zero, null, ref si, out pi);

【问题讨论】:

【参考方案1】:

在第二个参数中,您可以放置​​命令行选项。在第六个中,您可以放置​​创建选项,例如 CREATE_SUSPENDED。

CreateProcess(AppName, "WebStart", IntPtr.Zero, IntPtr.Zero, false, CREATE_SUSPENDED, IntPtr.Zero, null, ref si, out pi);

欲了解更多信息,请参阅http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx

【讨论】:

【参考方案2】:
public struct PROCESS_INFORMATION

    public IntPtr hProcess;
    public IntPtr hThread;
    public uint dwProcessId;
    public uint dwThreadId;


public struct STARTUPINFO

    public uint cb;
    public string lpReserved;
    public string lpDesktop;
    public string lpTitle;
    public uint dwX;
    public uint dwY;
    public uint dwXSize;
    public uint dwYSize;
    public uint dwXCountChars;
    public uint dwYCountChars;
    public uint dwFillAttribute;
    public uint dwFlags;
    public short wShowWindow;
    public short cbReserved2;
    public IntPtr lpReserved2;
    public IntPtr hStdInput;
    public IntPtr hStdOutput;
    public IntPtr hStdError;


public struct SECURITY_ATTRIBUTES

    public int length;
    public IntPtr lpSecurityDescriptor;
    public bool bInheritHandle;


using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace CreateProcess

    public static void Main()
    
        PROCESS_INFORMATION pi = new PROCESS_INFORMATION();
        STARTUPINFO si = new STARTUPINFO();

        CreateProcess("MapleStory.exe", "WebStart", IntPtr.Zero, IntPtr.Zero, false, 0, IntPtr.Zero, null, ref si, out pi);
    

    [DllImport("Kernel32.dll")]
    private static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo,out PROCESS_INFORMATION lpProcessInformation);

【讨论】:

【参考方案3】:
CreateProcess(AppName, "WebStart", IntPtr.Zero, IntPtr.Zero, false, 0, IntPtr.Zero, null, ref si, out pi);

【讨论】:

以上是关于createprocess中的Process.arguments?的主要内容,如果未能解决你的问题,请参考以下文章

CreateProcess 和 WaitForSingleObject 在两个 PDF 文件中的第二个失败

为啥 CreateProcess 中的 cmd.exe 的行为与 DOS 提示符不同?

CreateProcess 函数中的问题!

CreateProcess 的快速替代方案

将 CreateProcess 输入流重定向到文件

使用 createProcess() 运行批处理文件