2

我有一个 Windows 可执行文件 (whoami),它经常崩溃。从另一个进程调用它以获取有关当前用户和域的详细信息。我想知道失败时传递了哪些参数。

有谁知道包装进程并将其命令行参数写入日志同时仍调用进程的适当方法?

假设命令是这样使用的:'whoami.exe /all'

我希望存在一个脚本,而不是 whoami.exe (具有相同的文件名),它将将此调用写入日志,然后将调用传递给实际进程。

4

6 回答 6

1

您没有注意哪种编程语言。如果这是您想要的,则无法从 .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
}
于 2008-09-22T10:45:12.063 回答
1

我不认为使用“脚本”会起作用,因为中间体应该有一个 .exe 扩展名才能让你的策略起作用。

我会编写一个非常小的命令行程序来做到这一点;类似于以下内容(用 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.
于 2008-09-22T10:47:54.490 回答
1

你不能只改变调用程序来记录它用来调用进程的参数和退出代码吗?这比尝试深入研究 whoami.exe 要容易得多

于 2008-09-22T10:51:13.953 回答
1

从批处理文件:

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

需要注意的是,如果参数包含空格(并且您使用“转义传递 in”),您可能会遇到问题,因为命令行解析器基本上会取消转义它们,并且在传递给其他可执行文件之前应该重新转义它们。

于 2008-09-22T10:57:10.693 回答
0

查找 whoami.exe,备份它,用您自己的可执行文件替换它,然后查看使用它的参数做任何您喜欢的事情(也许将它们保存在文本文件中)。

于 2008-09-22T10:45:47.273 回答
0

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

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

于 2008-09-22T11:38:31.063 回答