GPUSwitch script

   This is windows scripting host script(in JScript), meant to be used for "dynamically" switch active GPUs in BOINC. It works in folloing way: uses MS XML COM object to modify cc_config.xml in appropriate way, then shutdowns BOINC core client(boinc.exe) with help of boinccmd.exe and start the client again, while BOINC Manager stays on. All operations are performed with single double-click on shortcut. Doesn't need additional software to be installed.
How to use it:
0. Ensure u have cc_config.xml file in your Data directory with at least following content:
   <cc_config>
      <options>
      </options>
   </cc_config>

1.Copy GPUSwitch.js in your BOINC Data directory(where cc_config.xml is).
2.Create number of shortcuts, according to your needs(Explanation follows).
 2a.Create shortcut(s) to the script file and place it wherever u like it. e.g on desktop. Target should look like this:
"D:\Sensitive data programs\BOINC\Data\GPUSwitch.js"
Note the quotes when the path to file contains spaces.
"Start in" field must contain path to Data directory in same manner as above.
 2b. Add additional parameters after script name(but outside quotes if they are present). Parameters are:
/i:x,y,z - where x, y and z are indexes of GPUs. E.g if u want to disable GPU 0, add /i:0, if u want to disable 1,2,4(assuming u have 5 or more GPUs) add /i:1,2,4 and so on. Any other values after semicolon or lack of characters will enable all GPUs. U will get notice about this with option to cancel operation. /s - parameter suppresses above mentioned notice. If u use only this parameter and no /i parameter, script will silently enable all GPUs, removing ignore_cuda_dev entries for cc_config.xml.
And finally, command in Target field should look like this:
for disabling GPU 0 and 1:
   "D:\Sensitive data programs\BOINC\Data\GPUSwitch.js" /i:0,1
for enabling all GPUs:
   "D:\Sensitive data programs\BOINC\Data\GPUSwitch.js" /s
or
   "D:\Sensitive data programs\BOINC\Data\GPUSwitch.js" /s /i
Keep in mind, parameter /s must precedes parameter /i (I leave it in this way to simplify parameter parsing, just simple rule to obey).
If u start script with no parameters it will be unhappy, will tell u some not very polite things and will exit. So parameters are a must.
3. Open GPUSwitch.js file, using any text editor, e.g Notepad(just be cautious using other editors - file must NOT be saved as Unicode text).
You will see following 4 variables almost on the top of the file:

   var targetFile = "cc_config.xml";
   var strBOINCDir = "D:\\Sensitive data programs\\BOINC";
   var strGUIRPCpasswd = "a24ab662ab245ba245eb270bc7e7c9fd";
   var strHost = "127.0.0.1";
   var uDelay = 5000;


   They need to be changed, or at least some of them, according to you setup. First, obviously is name of target file. We assume u don't need to change it. Second one is path to BOINC main directory(not Data directory, script is already there and does not need to know the path) in order to be able to use boinccmd.exe and boinc.exe(NOTE DOUBLE BACKSLASH IN PATH!). Third variable is your GUI RPC password, located in gui_rpc_auth.cfg file in BOINC Data directory(it may get automated too, but I decided to leave it to be added manually). Forth variable is host IP. Leave it as it is for localhost(script wont work on remote systems anyway, but I left is as parametric variable for future extends). Fifth variable is delay, in milliseconds between shutdown of core client and starting it again. It is needed, bcs core client needs some time to shut down. If it is not shut down, it won't start again. U can adjust this delay up or down, whichever suits u best. I picked up relatively high, but save value. The real delay needed may be very depending on the projects u run, number of client running overall host speed, current load etc. So, experiment with it, if doesn't work well(which means - client wont start after being shut down).
   In conclusion u MUST change second and third parameter and probably u may need to change last variable.
4. Wait for units to come and test it :) :) :) I got lucky to get some bunch of resends just after I solved the problem with client detaching from console window. It works for me great.
   I tried to find more elegant way to restart the client, but best achieved was to shutdown it thru RPC(via socket), and in PHP, bcs I was unable to find COM object allowing me to use sockets(well, there is one, but its functions need parameters passed by reference, which is impossible with JScript). I rewrote the script in PHP also, planning to use it as ActiveScript, bcs PHP does have sockets API, but I stuck in obstacle too - when PHP script is invoked with wscript, any COM instantiation makes the script to blow(generates exceptions and invokes my debugger). So JScript with external program call was most simple and most achievable way. It show console window twice, but its not that big PITA, as it actually saves file renaming or manual XML editing efforts.
   I tested this on XP x86 SP3, XP x64 SP2 and Windows 2003 R2 SP2 x64.

   As I write this, I realized, script is intended to be used when BOINC Manager is running. If u dont want stop/start operations of BOINC core client to executed, just remove those last three lines in GPUSwitch.js file:

WSHShell.Exec('"' + strBOINCDir + '\\boinccmd.exe" --host ' + strHost + ' --passwd ' + strGUIRPCpasswd + ' --quit');
WScript.Sleep(uDelay);
WSHShell.Exec('"' + strBOINCDir + '\\boinc" --redirectio --detach');


   I will extend the script further to detect is the Manager running in order to execute stop/start sequence or not.