This documentation is archived and is not being maintained.

How to: Create a Visual SourceSafe Batch File or Script

Visual Studio 2005

You can use the Visual SourceSafe command line to run a batch file or script that allows you to mechanize routine tasks. You can also include Visual SourceSafe commands in scripts that are run by other programs. Keep the following ideas in mind when preparing a batch file or script:

  • It is not desirable to include commands that require user input. You will usually want to disable input so that batch files can run undisturbed. See -I Option (Command Line).

  • Use exit codes in your batch files to test for command completion. The code 100 is usually used for an error.

  • If necessary, redirect output to a file so that you can keep a record of the batch operations to use in maintenance and testing.

To create a batch file or script:

  1. If you want to redirect output of your batch file or script to another file, see How to: Redirect Output.

  2. Determine a clear-cut set of commands to use in performing an operation that recurs frequently, for example, purging deleted items.

  3. Use a text editor to write the batch file or script, using the language of your choice.

  4. Start with an @echo off statement to turn off command echoing.

  5. Enter a statement for your first command, for example, the Status command shown in the example.

  6. Check exit codes for this command, as required.

  7. Include statements to handle the exit codes.

  8. Repeat steps 4 through 6 until you have included statements for all the commands to execute.

  9. Finish the file with and :END statement, or equivalent for the language you are using.

  10. Run your file from the command line to test its operation.


The following example shows a batch file that checks out files for user name Thomas. It demonstrates the use of the -O option to disable output, the -Y option to specify a user name, and the -C option to specify a comment. It also illustrates the use of the exit code of the Status command to determine if files are checked out.

If you type ss Checkout Help.c Help.H, and one of the two files is already checked out, Visual SourceSafe will check the other file out. The example batch file avoids this situation by checking the status of all the specified files and only checking them out if none of them is checked out.

@echo off
ss status -o- -yThomas %1 %2 %3 %4 %5 %6 %7 %8 %9
if errorlevel 100 goto BAD_FAILURE
if errorlevel 1 goto CHECKED_OUT

rem Exit code 0, no files were checked out
echo No specified files are checked out: checking all out.
ss checkout "-cChecked out automatically" -yThomas %1 %2 %3 %4 %5 %6 %7 %8 %9
goto END

rem Exit code 1, something is checked out
echo One or more files is checked out: quitting without checking anything out.
goto END

rem Exit code 100, something went wrong.
echo Visual SourceSafe could not run successfully


See Also