1
votes

I'm trying to run a .vbs file through a batch program (.bat). The catch is that the .vbs file and the .bat file are in different directories. Also, I want to use a variable path so that any user can launch my .bat program through the correct directory.

A simple version of the .bat script would look like:

cscript "C:\users\Username\Directory\file.vbs"

But, I want to use a variable for the directory so that it looks like this:

cscript %variable% test.vbs

Here's what I have so far:

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
1

1 Answers

1
votes

The "Users" directory of the current user is available in the USERPROFILE environment variable. The following would run the .vbs file from a batch file:

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