string cmd = Environment.CommandLine;
string[] strs = Environment.GetCommandLineArgs();

解决方案 »

  1.   

    Environment只对当前进程有用,如果是别的进程,用:
    String cmd = process.StartInfo.FileName + " " + process.StartInfo.Arguments;
      

  2.   

    cc 公主说的我早试过了    public static string RunningInstance() {
    Process[] processes = Process.GetProcesses();
    string s = null; foreach (Process p in processes) {
    s += p.WorkingSet + p.ProcessName + "\r\n" + p.StartInfo.FileName + " " + p.StartInfo.Arguments;
    } return s;
    }结果是p.StartInfo 里都是空值,因为StartInfo 是要传递的属性而不是用来获取已存在进程的属性
      

  3.   

    搞了半天终于找到一个可用的:using System;
    using System.Management;namespace ArLi.CommonPrj {
    public class GetCommandLineEx { public static readonly System.Version myVersion = new System.Version(1,1); /// <summary>
    /// LocalHost
    /// </summary>
    public static string CommandLine_WMI(){
    System.Management.ManagementScope ms = new System.Management.ManagementScope(@"\\.\root\cimv2");
    System.Management.ObjectQuery oq = new System.Management.ObjectQuery("select * from win32_process");
    ManagementObjectSearcher query = new ManagementObjectSearcher(ms,oq); ManagementObjectCollection moc = query.Get(); string s = ""; foreach(ManagementObject mo in moc) {
    s +=  (string)mo["CommandLine"] + "\r\n";
    }
    return s;
    }
    }
    }但是这个CommandLine 
    Data type: string
    Access type: Read-onlyCommand line used to start a specific process, if applicable. This property is new for Windows XP.这下可惨了,我的程序要求有win98 哩最少也要win2k 能跑呀,为为,大家一起帮帮忙想想啊
      

  4.   

    翻烂了WMI 也没找到更好的,而且根据 sysinternals 的 Process Explorer 的函数引用分析它使用的肯定不是wmi 而最有嫌疑的就是 getcommandline,可偶就是搞不出来,难道sysinternals 知道它有隐藏参数;-(
      

  5.   

    下面这篇文章是讲怎么从命令行获得标准输入输出的,是C++的,但也许对你有帮助。
    http://contextfree.net/wangyg/tech/myIDE.htm
      

  6.   

    最后的版本:
    http://zpcity.com/arli/commonprj/cls_GetCommandLineEx.cs可是还是没法用API 做到,WMI 做总是不好多个服务依存而且还必须是xp 以上,里面的CommandLine_API 哪位帮忙写一下!急用
      

  7.   

    you probably have to work with unsafe code, see this guy's suggestion:http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=F07Z5.83483%24lR2.2679507%40afrodite.telenet-ops.be
      

  8.   

    3q saucer,但是你的地址里面最重要的"See http://www.codepile.com/tric14.shtml for details"i can'n open... ;-(
      

  9.   

    seehttp://fravia.anticrack.de/natz_mp2.htm
      

  10.   

    http://www.csdn.net/Develop/Article/18/18722.shtm
      

  11.   

    This sample demonstrates how to get the command line another process was started with:
    http://mvps.org/win32/processes/remthread.html
      

  12.   

    谢谢 saucer,想不到读个命令行参数要这么累呀晕你给的 http://mvps.org/win32/processes/remthread.html 我已经下载,但是有个问题就是它的CreateRemoteThread 据我所知在win9x 是不受支持的。。另外,这个unsafe getcommandline 植入到目标进程中去run 是不是会有局限性,比如某些安全性比较强的程序可能会拒绝(没试过)这种入侵?谢谢大虾,这个是可以用的,比我的WMI 还多支持了win2k。还有没有简单一些的(可以不从commandline 入手,只要求获取该程序启动时的参数就行了),win32 真的没有获取参数支持?那wmi 怎么搞的到commandline 哩。。如果没有就结帐,3q all ;-)