【问题标题】:How to determine if command is executable?如何确定命令是否可执行?
【发布时间】:2018-01-06 13:39:59
【问题描述】:

如果您在默认的 Windows 安装中运行命令 shell,请键入 mspaint 并按 Enter,Paint 将启动。

有没有办法(以编程方式)确定命令是否可执行?

【问题讨论】:

  • 您可以运行where mspaint,然后检查%ERRORLEVEL% 变量,如果最后一个命令完成且没有错误(找到目标可执行文件)则为0,如果有错误(未找到)则为1。跨度>

标签: c# windows shell


【解决方案1】:

要分析给定文件,您可以使用作为Visual Studio 的一部分分发的dumpbin.exe 工具。

示例输出:

C:\>dumpbin z3.exe
Microsoft (R) COFF/PE Dumper Version 14.00.24213.1
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file z3.exe

File Type: EXECUTABLE IMAGE


C:\>dumpbin what.com
Microsoft (R) COFF/PE Dumper Version 14.00.24213.1
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file what.com
what.com : warning LNK4048: Invalid format file; ignored

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-31
    • 2012-11-30
    • 1970-01-01
    • 1970-01-01
    • 2012-04-08
    • 1970-01-01
    • 2019-03-11
    相关资源
    最近更新 更多