Windows Script Host 在启动时找不到文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6292729/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Windows Script Host cannot find the file on startup
提问by bendebass
I am having here a vbs-file which starts a batch script. The batch should run invisible, so i use this vbs-script:
我在这里有一个启动批处理脚本的 vbs 文件。批处理应该不可见,所以我使用这个 vbs 脚本:
WScript.CreateObject( "WScript.Shell" ).Run "loop.bat",0,0
The vbs is registered to the run-key in the registry-
vbs 注册到注册表中的运行键 -
Everytime on startup it tells me that he cannot find the specified file. Maybe the Windows Script Host is starting to late for my vbs-script?
每次启动时它都告诉我他找不到指定的文件。也许我的 vbs 脚本的 Windows 脚本宿主开始迟到了?
What should I do?
我该怎么办?
vbs with delayed start? This needs another loop, but my script shall be invisible.
vbs 延迟启动?这需要另一个循环,但我的脚本将不可见。
vbs in the startupfolder? Better taking the registry. For other reasons I cannot use the startupfolder.
启动文件夹中的vbs?最好使用注册表。由于其他原因,我无法使用启动文件夹。
Thanks for your answers :)
感谢您的回答:)
回答by SmithMart
I know it's old... But i thought I'd put this in in case anyone stumbles here.
我知道它很旧......但我想我会把它放在以防有人在这里绊倒。
if you add something to run, when it starts unless otherwise specified it's working directory is C:\Windows\System32 so if you point to a file, "mybat.bat" it will assume it's in c:\windows\system32\mybat.bat
如果添加要运行的内容,除非另有说明,否则它在启动时的工作目录是 C:\Windows\System32,因此如果指向一个文件“mybat.bat”,它将假定它在 c:\windows\system32\mybat 中。蝙蝠
that's why you need to specify the whole path in the vbs.
这就是为什么您需要在 vbs 中指定整个路径的原因。
if you are in a bat file then add this to the top of your file:
如果您在 bat 文件中,则将其添加到文件顶部:
PUSHD %~dp0
Martyn
马丁