简体   繁体   中英

Unable to run .vbs script from my C# program: “The system cannot find the file specified.”

I'm trying to run a easy .vbs script from my C# program, but I keep getting this error.

I'm 100% sure my path is correct! Does anybody know anything about this problem? my run.vbs alone runs fine (also the system_logged.bat runs fine)

Inside the .vbs I call a batch file and dump the error logs, nothing more.

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

Since your error message reports that the error is coming from this line:

obj = WshShell.Run("system_logged.bat", 0)

my assumption is that the script cannot locate system_logged.bat . Try supplying the full path to the bat file in your script. If there are spaces in the path, you'll need to enclose it in quotes. In VBScript, you'll need to escape any quotes in string literals by doubling them:

obj = WshShell.Run("""c:\path with spaces\system_logged.bat""", 0)

The reason it may work when running it on its own could be because of the execution context in which it's run. When launched from your c# app, the default working directory could be different than what WScript uses when launched on its own.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM