批处理文件无法打开隐藏的.vbs文件

时间:2017-04-21 18:09:53

标签: batch-file vbscript

我有一个制作.vbs文件的批处理文件,然后打算将其打开。它们都在同一个文件夹中。我尝试使用start,但由于某种原因它根本无法运作。我也试过cscript,但由于脚本应该被隐藏,所以这也不起作用。如果我尝试手动运行vbs文件,它可以工作。

代码:

@echo off
tasklist | find "wscript.exe" >nul: && goto runningalr

:reset
type nul > sound.vbs
(echo Set Sound = CreateObject("WMPlayer.OCX.7"^))>>sound.vbs

:begin
set /p loop=Do you want the music to repeat? (y/n) ... 
if /i %loop%==y goto repeat
if /i %loop%==n goto begin1
goto begin

:repeat
(echo do until false)>>sound.vbs
goto begin1

:begin1
set /p damd=The music's directory? (type "exit" if no more) ... 
if /i %damd%==exit goto start
( echo Sound.URL = "%damd%"
  echo Sound.Controls.play
  echo do while Sound.currentmedia.duration = 0
  echo wscript.sleep 100
  echo loop
  echo wscript.sleep (int(Sound.currentmedia.duration^)+1^)*1000)>>sound.vbs
goto begin1

:runningalr
set /p kill=Music already playing. Do you want to stop it? (y/n) ... 
if %kill%==y taskkill /f /im wscript.exe && exit
if %kill%==n goto gonnaexit

:gonnaexit
<nul set /p "=Press any key to exit ... "
pause >nul
exit

:start
if /i %loop%==y (echo loop)>>sound.vbs
start C:\Users\User\Desktop\server\sound.vbs

为什么没有start为我工作,哪些有效?

2 个答案:

答案 0 :(得分:0)

而不仅仅是&#34;找到wscript&#34;尝试使用&#34;找到%WINDIR%/ System32 / wscript.exe / I&#34;

您可能还需要以管理员身份运行脚本,但这不太可能。

答案 1 :(得分:0)

您使用start提供了专用路径,但是您将vbs脚本写入当前工作目录。以下行从该工作目录开始:

start "" "%~dp0sound.vbs"