in

ASP.NET Weblogs

Sijin Joseph's blog

My experiences with .Net

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]);
       }
  }

Comments

 

jone said:

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?

August 19, 2007 10:26 AM
 

Sijin Joseph said:

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

August 20, 2007 1:38 PM
 

Kavitha said:

Hi,

I was trying to do a VSS checkin checkout automation (mailing the admin once the checkin or checkout done on the database).. i copied the source code from this link

msdn.microsoft.com/.../bb509341.aspx

I created a activeX dll as metnioned in the above link and when i tried to open the database the init function is called..but when i tried to add file/checkout any files..the function which handles these events are not called at all.. any clue abt why?

May 5, 2008 7:26 AM
 

Ilia said:

Did you ever come across any documentation on those COM interfaces (SourceSafe and Outlook.Application)?

SourceSafe in particular?

I have been scaring for code snippets to figure out how to use it and that is just not doing it for me anymore.

August 1, 2008 11:24 AM

Leave a Comment

(required)  
(optional)
(required)  
Add