Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 使用可变路径从.bat运行.vbs文件_Batch File_Vbscript_Cmd - Fatal编程技术网

Batch file 使用可变路径从.bat运行.vbs文件

Batch file 使用可变路径从.bat运行.vbs文件,batch-file,vbscript,cmd,Batch File,Vbscript,Cmd,我正试图通过批处理程序(.bat)运行.vbs文件。问题是.vbs文件和.bat文件位于不同的目录中。另外,我想使用一个变量路径,这样任何用户都可以通过正确的目录启动我的.bat程序 .bat脚本的简单版本如下所示: cscript "C:\users\Username\Directory\file.vbs" 但是,我想为目录使用一个变量,使其看起来像这样: cscript %variable% test.vbs 以下是我目前掌握的情况: for /f "tokens=3 delims=\"

我正试图通过批处理程序(.bat)运行.vbs文件。问题是.vbs文件和.bat文件位于不同的目录中。另外,我想使用一个变量路径,这样任何用户都可以通过正确的目录启动我的.bat程序

.bat脚本的简单版本如下所示:

cscript "C:\users\Username\Directory\file.vbs"
但是,我想为目录使用一个变量,使其看起来像这样:

cscript %variable% test.vbs
以下是我目前掌握的情况:

for /f "tokens=3 delims=\" %%a in ("%cd%") do set user=%%a
set "base=c:\users\"
set "end=\Folder 1\Folder 2\"
set "basePath = %base%%user%%end%"
set "vbsName=test.vbs"
cscript %basePath% %vbsName%
pause
当前用户的“用户”目录可在
USERPROFILE
环境变量中找到。以下操作将从批处理文件运行.vbs文件:

cscript "%USERPROFILE%\Folder 1\Folder 2\test.vbs"

工作起来很有魅力!非常感谢你!伟大的请继续并将此问题标记为已回答。