VSS Automation script

In our company we have a policy of creating a checkin mail that describes the files that you are checking in and what changes or bugs have been fixed in that checkin. The process of creating the mail involved opening VSS and then getting a list of all checked out files and then copying and pasting that to the mail. I've always wanted to get into windows scripting and i thought what better oppurtunity than this. So i wrote this small script that gets a list of all checked out files from VSS and then creates a new mail with the required info already filled in.
 
 
  var oVss = new ActiveXObject("SourceSafe");
  oVss.Open("
<Insert path to srcsafe.ini>");
  var oProj = oVss.VSSItem("<Insert project path e.g. $/");
    
  var allProjects = new Array();
  allProjects = GetAllProjects(oProj,allProjects);
    
  var output = "";
  var projItem;
  var projEnumerator = new Enumerator(allProjects);
  for (; !projEnumerator.atEnd() ; projEnumerator.moveNext() )
  {
      projItem = projEnumerator.item();
      var checkouts = GetCheckedOutFiles(projItem);
   
      if(checkouts.length > 0)
      {
          output += projItem.Spec + "\n";
          var checkoutEnumerator = new Enumerator(checkouts);
          for(;!checkoutEnumerator.atEnd();checkoutEnumerator.moveNext())
          {
              var checkoutItem = checkoutEnumerator.item();
              output += "\t" + checkoutItem + "\n";
          }
    
          output += "\n";
      }
  }
  
  var olApp = new ActiveXObject("Outlook.Application");
  var mailItem = olApp.CreateItem(0 /*olMailItem*/);
  mailItem.Recipients.Add("<Insert e-mail address to send mail to>");
  mailItem.Body = "\n" + output;
  mailItem.Display();
  
  function GetCheckedOutFiles( projectItem )
  {
      var checkouts = new Array();
      var itemEnumerator = new Enumerator(projectItem.items(false));
      for(; !itemEnumerator.atEnd(); itemEnumerator.moveNext())
      {
          var item = itemEnumerator.item();
          //File
          if(item.Type == 1/*VSSITEM_FILE*/ && item.IsCheckedOut == 2 /*VSSFILE_CHECKEDOUT_ME*/)
          {
               checkouts.push(item.Name);
           }
       }
       return checkouts;
  } 
  
  function GetAllProjects( rootItem )
  {
      var projects = new Array();
      var items = new Enumerator(rootItem.items(false));
   
      for(;!items.atEnd();items.moveNext())
      {
          var item = items.item();
          //Project
          if(item.Type == 0 /*VSSITEM_PROJECT*/)
          {
              projects.push(item);
      
              var subProjects = GetAllProjects(item);
              var subProjectEnumerator = new Enumerator(subProjects);
              for(;!subProjectEnumerator.atEnd();subProjectEnumerator.moveNext())
              {
                  var subProjectItem = subProjectEnumerator.item();
                  projects.push(subProjectItem);
              }
          }
   }
    return projects;
  }
  
  function printItems(items, prop)
  {
      var itemEnumerator = new Enumerator(items);
      for(;!itemEnumerator.atEnd();itemEnumerator.moveNext() )
      {
          var item = itemEnumerator.item();
          WScript.Echo(item[prop]);
       }
  }

3 Comments

  • i made copy of your script, and save it as vssCheckInOut.vbs.
    but when i run th escript i get error :
    C:\jone\script\vssCheckInOut.vbs(1, 29) Microsoft VBScript compilation error: Exp
    ected end of statement

    can you help to find what i make wrong?

  • Hi jone - the script is written using jscript and not vbscript

  • please proivde me the code to trigger a mail through vss autonotifying the filesl so that the mail can send info to all the user about files checkin and checked out

Comments have been disabled for this content.