包装一个可执行文件来诊断它的调用

我有一个Windows可执行文件(whoami),每隔一段时间就会崩溃。 从另一个进程调用它来获取有关当前用户和域的详细信息。 我想知道什么parameter passing失败时。

有没有人知道一个合适的方式来包装进程,并将其写入命令行参数logging,同时仍然调用进程?

说这个命令是这样使用的:'whoami.exe / all'

我想要一个脚本存在,而不是whoami.exe(具有相同的文件名),这将写入此调用logging,然后将调用传递给实际的过程。

从批处理文件:

echo Parameters: %* >> logfile.txt whoami.exe %* 

注意,如果参数中包含空格,那么您可能会遇到问题(因为命令行解析器基本上将它们转义出来,所以在传递给其他可执行文件之前,它们应该被重新转义)。

你没有注意到哪种编程语言。 如果这是你想要的,那么从.bat文件无法做到,但是你可以用任何编程语言来完成。 C中的示例:

 int main(int argc, void **argv) { // dump contents of argv to some log file int i=0; for (i=0; i<argc; i++) printf("Argument #%d: %s\n", argv[i]); // run the 'real' program, giving it the rest of argv vector (1+) // for example spawn, exec or system() functions can do it return 0; // or you can do a blocking call, and pick the return value from the program } 

我不认为使用“脚本”将工作,因为中间应该有一个扩展名为您的工作。

我会写一个非常小的命令行程序来做到这一点; 像下面这样的东西(使用Delphi / Virtual Pascal编写,所以它将产生一个Win32可执行文件,但是任何编译语言都应该这样做):

 program PassThrough; uses Dos; // Imports the Exec routine const PassTo = 'Original.exe'; // The program you really want to call var CommandLine: String; i: Integer; f: Text; begin CommandLine := ''; for i := 1 to ParamCount do CommandLine := CommandLine + ParamStr(i) + ' '; Assign(f,'Passthrough.log'); Append(f); Writeln(f, CommandLine); // Write a line in the log Close(f); Exec(PassTo, CommandLine); // Run the intended program end. 

你不能只是改变调用程序来记录它用来调用进程的参数和退出代码吗? 这将比试图挖掘whoami.exe更容易

找到whoami.exe,将它备份,用自己的可执行文件替换它,然后用参数来查看你喜欢的任何东西(也许把它们保存在一个文本文件中)。

如果可以重现崩溃,请在崩溃的进程终止之前使用Process Explorer来查看其命令行。

http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx