VBscript - “The system cannot find the file specified”

假装没事ソ 提交于 2019-12-23 16:43:53

问题


I'm trying to write a short VBScript, which opens "calc.exe" and "wordpad.exe". Well the problem is that VBScript won't let me open "wordpad.exe". I've tried to run the script as an admin, but this doesn't helped.

My Script looks like this:

Set WshShell = WScript.CreateObject("WScript.Shell")
WSHShell.Run "C:\Program Files\Windows NT\Accessories\wordpad.exe"
WSHShell.Run "C:\Windows\System32\calc.exe"
x=msgbox("Test",4096,Test) 

I've also tried to define the path like this:

WSHShell.Run ""C:\Program Files\Windows NT\Accessories\wordpad.exe""

Also not working. I'm getting the message "Expected end of statement"

Is there a solution to open "wordpad.exe" by its path?

Kind regards


回答1:


The shell uses blanks/spaces as separators. So paths containing blanks/spaces need to be quoted. The way to quote " in VBScript string literals is to double them. So:

WSHShell.Run "C:\Program Files\Windows NT\Accessories\wordpad.exe"
==>
WSHShell.Run """C:\Program Files\Windows NT\Accessories\wordpad.exe"""


来源:https://stackoverflow.com/questions/33389660/vbscript-the-system-cannot-find-the-file-specified

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!