RSmura
09-11-2006, 10:42 AM
I manage a bunch of clients, so touching all of them isn't practicle. That being said, I still have to make changes, like when our TEAM CAPTAIN MovieMan tells me I gotta get all my boxes off the "cheating" crunchers. Ok, here is the easy way:
@echo off
REM The next line checks to see if the "updates" folder exists and creates it if it does not.
if not exist c:\updates md c:\updates
REM the next line checks to see if boincupd.txt exists and exits the script if it does
if exist c:\updates\boincupd.txt exit
REM The next line stops the BOINC service from running
net stop BOINC
REM The next line runs a java script that kills boincmgr.exe using a .js included below:
CScript s:\KillProc.js boincmgr.exe
REM The next line copies the original cruncher files that you have placed at \\machinename\share\folder\ and overwrites any current files
copy \\machinename\share\folder\boinc.* "C:\Program Files\BOINC" /y
REM The next line creates that boincupd.txt so this won't run but once
dir "c:\Program Files\BOINC" > c:\updates\boincupd.txt
REM The next line starts your crunchers back up with stock files
net start BOINC
REM The next line is just your exit point if the files exist.
:EXIT
Copy and paste the above into notepad and save it as a .CMD file. This will make it execute when run. CALL the file from your logon script if you use one. i.e. if you save it as S:\boincupd.CMD then your logon script would say:
CALL "S:\boincupd.cmd"
Below is the .js file you will need to kill the running boincmgr. follow the directions inside the /*//////////////// lines... Keep in mind that you must place this .js file on a share that everyone can access since your logon script is going to call the .CMD that is going to call this .js on EVERY MACHINE.
/*////////////////////////////////////////////////////////////////////
FileName: KillProc.js
Copy this script to dir in path (C:\, C:\Winnt or C:\Windows,...)
From command line:
C:\>KillProc notepad.exe
Sript assumes:
- WMI (WinXP, Win2K or WinNT with WMI core),
- User running it must have administrative privileges.
*/////////////////////////////////////////////////////////////////////
var oShell = new ActiveXObject("Wscript.Shell");
var oArgs = WScript.Arguments;
var sArgsAry = new Array();
var sArgsLine = "";
// --- Make sure there are comand line parameters:
if (oArgs.length==0) {
sMsg = "Usage: \n\tC:\\>KillProc notepad.exe [winword.exe ...]"
WScript.Echo(sMsg);
WScript.Quit();
}
// --- Collect script arguments (if any):
for (var i=0; i<oArgs.length ; i++) {
// Collect passed arguments
sArgsLine += "\"" + oArgs(i) + "\" ";
sArgsAry[sArgsAry.length] = oArgs(i)
}
// --- Ensure that CScript.exe is the host:
if (!isCScript()) {
var sMsg = "CScript.exe must be used to run this script.\n\n";
sMsg += "To set CScript as the default host:\n\n";
sMsg += "C:\\>WScript //H:CScript";
WScript.Echo(sMsg);
WScript.Quit();
}
// --- Kill process(es):
for (var i=0; i<sArgsAry.length ; i++) {
WScript.Echo("Killing (if any): " + sArgsAry[i]);
KillProcess(sArgsAry[i]);
}
function KillProcess(sProg) {
try { var oWMI = GetObject("winmgmts:{impersonationLevel=impersonate,(Debug)}");
} catch(e) { return; }
var sQuery = "select * from win32_process where name='" + sProg + "'";
try { var oEnm = new Enumerator(oWMI.execquery(sQuery));
} catch(e) { return; }
for (;!oEnm.atEnd();oEnm.moveNext()) { oEnm.item().terminate(); }
}
function isCScript() { return (/cscript.exe$/i).test(WScript.FullName); }
// Branimir
If you have any questions, please feel free to ask me although I am not a scripting or Java expert.
@echo off
REM The next line checks to see if the "updates" folder exists and creates it if it does not.
if not exist c:\updates md c:\updates
REM the next line checks to see if boincupd.txt exists and exits the script if it does
if exist c:\updates\boincupd.txt exit
REM The next line stops the BOINC service from running
net stop BOINC
REM The next line runs a java script that kills boincmgr.exe using a .js included below:
CScript s:\KillProc.js boincmgr.exe
REM The next line copies the original cruncher files that you have placed at \\machinename\share\folder\ and overwrites any current files
copy \\machinename\share\folder\boinc.* "C:\Program Files\BOINC" /y
REM The next line creates that boincupd.txt so this won't run but once
dir "c:\Program Files\BOINC" > c:\updates\boincupd.txt
REM The next line starts your crunchers back up with stock files
net start BOINC
REM The next line is just your exit point if the files exist.
:EXIT
Copy and paste the above into notepad and save it as a .CMD file. This will make it execute when run. CALL the file from your logon script if you use one. i.e. if you save it as S:\boincupd.CMD then your logon script would say:
CALL "S:\boincupd.cmd"
Below is the .js file you will need to kill the running boincmgr. follow the directions inside the /*//////////////// lines... Keep in mind that you must place this .js file on a share that everyone can access since your logon script is going to call the .CMD that is going to call this .js on EVERY MACHINE.
/*////////////////////////////////////////////////////////////////////
FileName: KillProc.js
Copy this script to dir in path (C:\, C:\Winnt or C:\Windows,...)
From command line:
C:\>KillProc notepad.exe
Sript assumes:
- WMI (WinXP, Win2K or WinNT with WMI core),
- User running it must have administrative privileges.
*/////////////////////////////////////////////////////////////////////
var oShell = new ActiveXObject("Wscript.Shell");
var oArgs = WScript.Arguments;
var sArgsAry = new Array();
var sArgsLine = "";
// --- Make sure there are comand line parameters:
if (oArgs.length==0) {
sMsg = "Usage: \n\tC:\\>KillProc notepad.exe [winword.exe ...]"
WScript.Echo(sMsg);
WScript.Quit();
}
// --- Collect script arguments (if any):
for (var i=0; i<oArgs.length ; i++) {
// Collect passed arguments
sArgsLine += "\"" + oArgs(i) + "\" ";
sArgsAry[sArgsAry.length] = oArgs(i)
}
// --- Ensure that CScript.exe is the host:
if (!isCScript()) {
var sMsg = "CScript.exe must be used to run this script.\n\n";
sMsg += "To set CScript as the default host:\n\n";
sMsg += "C:\\>WScript //H:CScript";
WScript.Echo(sMsg);
WScript.Quit();
}
// --- Kill process(es):
for (var i=0; i<sArgsAry.length ; i++) {
WScript.Echo("Killing (if any): " + sArgsAry[i]);
KillProcess(sArgsAry[i]);
}
function KillProcess(sProg) {
try { var oWMI = GetObject("winmgmts:{impersonationLevel=impersonate,(Debug)}");
} catch(e) { return; }
var sQuery = "select * from win32_process where name='" + sProg + "'";
try { var oEnm = new Enumerator(oWMI.execquery(sQuery));
} catch(e) { return; }
for (;!oEnm.atEnd();oEnm.moveNext()) { oEnm.item().terminate(); }
}
function isCScript() { return (/cscript.exe$/i).test(WScript.FullName); }
// Branimir
If you have any questions, please feel free to ask me although I am not a scripting or Java expert.