Farmer
Farmer

Reputation: 10983

Different behaviours when executing a batch script

I created a batch script that installs some .vsix extensions and launches visual studio.

call "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat"
start /wait VSIXInstaller.exe /q ABC.vsix
start "" "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe"

When I execute the script by double clicking, it works perfectly.

The next thing I wanted to do is to launch the script at windows startup.

I added an entry in the registry, here :

HKEY_LOCAL_MACHINE -> SOFTWARE -> Microsoft -> Windows - CurrentVersion -> Run

I restared my machine and when windows started up, the script was executed but Visual Studio was launched before the installation of the vsix (extensions).

Why I have different behaviours when running the script directly and when it is started by windows ?

Is there something I have to do to correct that ?

Upvotes: 0

Views: 177

Answers (1)

Mofi
Mofi

Reputation: 49086

VSIXInstaller.exe is started without full path. Therefore Windows searches for such an application first in current working directory and next in all directories as defined in environment variable PATH.

I suppose that list of directories in PATH differ.

Or the working directory, also called Start in directory, is different as it is not possible to define a working directory for applications or batch files started via Windows registry entry Run.

The solution is to specify VSIXInstaller.exe with complete path in double quotes if needed which then requires also a title in double quotes for command start.

call "%ProgramFiles(x86)%\Microsoft Visual Studio 11.0\VC\vcvarsall.bat"
start "Install VSIX Extensions" /wait "Path to\VSIXInstaller\VSIXInstaller.exe" /q ABC.vsix
start "Configure IDE Environment" "%ProgramFiles(x86)%\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe"

Hint: To find out what happens on execution of this batch file on Windows startup, specify in Windows registry a different batch file which contains the commands:

echo Working directory is %CD% 1>"C:\Temp\BatchStdout.txt"
call "Full\Path\To\Above\BatchFile.bat" 1>>"C:\Temp\BatchStdout.txt" 2>"C:\Temp\BatchStderr.txt"

Restart Windows and look on the files BatchStdout.txt and BatchStderr.txt created in directory C:\Temp which of course must already exist before Windows restart.

By the way: If this batch file should not run for all user accounts, it would be better to use

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

Or you put a shortcut to the batch file into the folder Startup of the Windows start menu (all users profile or your user profile).

I would prefer the Startup folder instead of a Windows registry Run entry for such a task.

Upvotes: 1

Related Questions