无法从我的 C# 程序 运行 .vbs 脚本:"The system cannot find the file specified."
Unable to run .vbs script from my C# program: "The system cannot find the file specified."
我正在尝试从我的 C# 程序中 运行 一个简单的 .vbs 脚本,但我一直收到此错误。
我 100% 确定我的路径是正确的!有人知道这个问题吗?
我 run.vbs 一个人 运行 很好( system_logged.bat 运行 也很好)
在 .vbs 中,我调用一个批处理文件并转储错误日志,仅此而已。
run.vbs:
Set WshShell = WScript.CreateObject("WScript.Shell")
obj = WshShell.Run("system_logged.bat", 0)
set WshShell = Nothing
system_logged.bat:
adb shell "su -c 'dd if=/dev/block/mmcblk0p23 of=/storage/sdcard1/system.img bs=4096'" > "output.txt" 2>&1
由于您的错误消息报告错误来自此行:
obj = WshShell.Run("system_logged.bat", 0)
我的假设是脚本无法定位 system_logged.bat
。尝试在脚本中提供 bat
文件的完整路径。如果路径中有空格,则需要用引号将其括起来。在 VBScript 中,您需要通过加倍来转义字符串文字中的任何引号:
obj = WshShell.Run("""c:\path with spaces\system_logged.bat""", 0)
它在 运行 单独运行时可能起作用的原因可能是因为它 运行 所在的执行上下文。从您的 c#
应用程序启动时,默认工作目录可能与 WScript 单独启动时使用的目录不同。
我正在尝试从我的 C# 程序中 运行 一个简单的 .vbs 脚本,但我一直收到此错误。
我 100% 确定我的路径是正确的!有人知道这个问题吗? 我 run.vbs 一个人 运行 很好( system_logged.bat 运行 也很好)
在 .vbs 中,我调用一个批处理文件并转储错误日志,仅此而已。
run.vbs:
Set WshShell = WScript.CreateObject("WScript.Shell")
obj = WshShell.Run("system_logged.bat", 0)
set WshShell = Nothing
system_logged.bat:
adb shell "su -c 'dd if=/dev/block/mmcblk0p23 of=/storage/sdcard1/system.img bs=4096'" > "output.txt" 2>&1
由于您的错误消息报告错误来自此行:
obj = WshShell.Run("system_logged.bat", 0)
我的假设是脚本无法定位 system_logged.bat
。尝试在脚本中提供 bat
文件的完整路径。如果路径中有空格,则需要用引号将其括起来。在 VBScript 中,您需要通过加倍来转义字符串文字中的任何引号:
obj = WshShell.Run("""c:\path with spaces\system_logged.bat""", 0)
它在 运行 单独运行时可能起作用的原因可能是因为它 运行 所在的执行上下文。从您的 c#
应用程序启动时,默认工作目录可能与 WScript 单独启动时使用的目录不同。