我正在尝试使用WMIC从远程服务器执行批处理脚本,并且附加的输出是' WMIC_Output.JPG'
我从命令看到的输出不准确。当我在实际服务器上运行相同的脚本时,我可以看到正确的输出。请参阅随附的屏幕截图' Output.JPG'
现在我假设远程执行脚本给我进程ID和脚本退出状态。
请让我知道要包含的WMIC参数/开关以获得所需的输出。
-Abhi
答案 0 :(得分:0)
通过为/k
指定cmd.exe
opiton来执行此操作。您还需要使用引号来保护批处理文件名称中的空格。
C:\Users\user>wmic /node:localhost process call create 'cmd.exe /k "C:\\Users\user\\AWS__APIGATEWAY - 4xerror - Windows.bat" '
<强>详细信息:强>
执行时......
C:\Users\user>wmic /node:localhost process call create "cmd.exe C:\\Users\user\\AWS__APIGATEWAY - 4xerror - Windows.bat"
Executing (Win32_Process)->Create()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
ProcessId = 2192;
ReturnValue = 0;
};
cmd.exe
需要/k
选项。当我们添加&#39; / k&#39;选项......
C:\Users\user>wmic /node:localhost process call create "cmd.exe /k C:\\Users\user\\AWS__APIGATEWAY - 4xerror - Windows.bat"
Executing (Win32_Process)->Create()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
ProcessId = 4064;
ReturnValue = 0;
};
并在弹出的窗口中显示:
'C:\\Users\user\\AWS__APIGATEWAY' is not recognized as an internal or external command,
operable program or batch file.
C:\Windows\system32>
当我们在批处理文件名称周围加上引号时,它会正确执行并在新的cmd窗口中生成输出:
C:\Users\user>wmic /node:localhost process call create 'cmd.exe /k "C:\\Users\user\\AWS__APIGATEWAY - 4xerror - Windows.bat" '
Executing (Win32_Process)->Create()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
ProcessId = 5788;
ReturnValue = 0;
};
答案 1 :(得分:0)
因为npocmaka告诉你sendoutput到一个文件,然后读取它。 wmic
转义很难。请尝试
set "fileout=c:\....\output.txt"
wmic /node:dnvprdsis11.....org process call create "cmd /c E:\\sitescope\\...Windows.bat > \"%fileout%\"" >NUL 2>NUL
ping localhost -n 2 -w 300 >NUL
if exist "%fileout%" type "%fileout%"
... > \"%fileout%\ ..."
可能还需要转义... ^> \"%fileout%\" ...