//////////////////////////////////////////////////////////// // REGION_SWITCHER.js // // Allow for fast region switching in Windows. // // Author: A Better Solution, Inc. // : support@abs-consulting.com // : www.abs-consulting.com // Date : July 07, 2005 //////////////////////////////////////////////////////////// // History: 07/07/2005 : Created for A Better Solution, Inc. // : 07/14/2005 : Added BUILD_DYNAMIC_LIST // : (set to "TRUE" or "FALSE") //////////////////////////////////////////////////////////// //////////////////// // Static Data //////////////////// var vbOKOnly = 0; var vbOKCancel = 1; var vbAbortRetryIgnore = 2; var vbYesNoCancel = 3; var vbYesNo = 4; var vbRetryCancel = 5; var vbOK = 1; var vbCancel = 2; var vbAbort = 3; var vbRetry = 4; var vbIgnore = 5; var vbYes = 6; var vbNo = 7; var vbStop = 16; var vbQuestion = 32; var vbError = 48; var vbInformation = 64; var attrReadOnly = 1; var attrHidden = 2; var attrArchive = 32; var forReading = 1; var forWriting = 2; var forAppending = 8; var FALSE = 0; var TRUE = 1; var fsoABS = new ActiveXObject("Scripting.FileSystemObject"); var WSHShell = WScript.CreateObject("WScript.Shell"); ///////////////////// // ClearCase Stuff ///////////////////// var strCCRegKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Atria\\ClearCase\\CurrentVersion\\Region"; var strCCCurrentRegion = "??"; var strCCNextRegion = "??"; ///////////////////////////////////////////////////////////////////////////////////// // You could build the list dynamically, but usually clients want a limited list and // they do NOT ever want the UNIX regions listed, so a list is provided. // If you ant the list build Dynamically, set BUILD_DYNAMIC_LIST to TRUE; ///////////////////////////////////////////////////////////////////////////////////// var BUILD_DYNAMIC_LIST = FALSE; var strCCRegionList = "region_1,regino_2,region_3"; ///////////////////////////////////////////////////////////////////////////////////// var TFile = "c:\\tmp_switch_reg.txt"; var WhichOne = ""; var BoxTitle = "ABS Region Switch"; var ErrorMsg_1 = "Unable to read current version value in registry:\n\n ClearCase might not be installed on this machine."; var ErrorMsg_2 = "Unable to list any ClearCase region:\n\n ClearCase might not be installed on this machine."; var ErrorMsg_3 = "Unable to update version registry:\n\n Do you have local admin rights to the machine?"; var ErrorMsg_4 = "No Region selected, Nothing done."; var question = ""; var jsCrLf = ""+String.fromCharCode(13,10)+""; ////////////////////////////////////// // Main Code ////////////////////////////////////// ///////////////////////////////////////////// // Read current ClearCase region to display ///////////////////////////////////////////// try { strCCCurrentRegion = WSHShell.RegRead(strCCRegKey); } catch(e) { WSHShell.Popup(ErrorMsg_1, 0, BoxTitle, vbOKCancel + vbError); WScript.Quit(); } ////////////////////////////////////////////////////////////////// // Show current region and have user confirm they want to switch ////////////////////////////////////////////////////////////////// question ="The current ClearCase region is:\n\n\t("+strCCCurrentRegion+")\n\n"; question += "Are you sure you want to switch from this region?"; if (WSHShell.Popup(question, 0, BoxTitle, vbYesNo + vbInformation) == vbNo) { WScript.Quit(); } /////////////////////////////////////////////// // Select new Region from the list of regions /////////////////////////////////////////////// if (BUILD_DYNAMIC_LIST == TRUE) { ///////////////////////////////////////////////////// // Build a list from the cleartool lsregion command ///////////////////////////////////////////////////// var objExecObject = WSHShell.Exec("cleartool lsregion -s"); strCCRegionList = objExecObject.StdOut.ReadAll(); var ii = strCCRegionList.indexOf(jsCrLf); while (ii != -1) { strCCRegionList = strCCRegionList.substr(0, ii) + "," + strCCRegionList.substr(ii+2, strCCRegionList.length ); ii = strCCRegionList.indexOf(jsCrLf); } ///////////////////////// // rip last ',' and EOF ///////////////////////// strCCRegionList= strCCRegionList.substr(0, (strCCRegionList.length)); } ////////////////////////////////////////// // Selct from the static or dynamic list ////////////////////////////////////////// WhichOne = "clearprompt.exe list -outfile \""+TFile+"\" -items \""+strCCRegionList+"\" -pro \"Which region?\" -pre"; if (WSHShell.Run(WhichOne, 3, TRUE) != 0) { WSHShell.Popup(ErrorMsg_4, 0, BoxTitle, vbOKOnly + vbInformation); WScript.Quit(); } try { f = fsoABS.OpenTextFile(TFile, 1, false); strCCNextRegion = f.ReadAll(); strCCNextRegion = strCCNextRegion.substr(0, (strCCNextRegion.length - 2)); f.Close(); fsoABS.DeleteFile(TFile); } catch(e) { WSHShell.Popup(ErrorMsg_4, 0, BoxTitle, vbOKOnly + vbInformation); WScript.Quit(); } ///////////////////////////////////////////// // Set to the new region that was selected ///////////////////////////////////////////// try { WSHShell.RegWrite(strCCRegKey, strCCNextRegion); } catch(e) { WSHShell.Popup(ErrorMsg_3, 0, BoxTitle, vbOKCancel + vbError); WScript.Quit(); } WSHShell.Popup("The ClearCase region was changed to ("+strCCNextRegion+").", 0, BoxTitle, vbOKOnly + vbInformation); WScript.Quit();