
end task Outlook.exe from command line?
Quote:
> How do you stop a program or end task from the command
> line. For example, I have a small batch to clean out a lot
> of temporary files, but many times the files are in use by
> various programs, so I would like to stop those programs
> so that I can delete these files. Starting them back up is
> easy. I found just dragging shortcuts to the programs,
> then looking at the properties of the shortcut gave me a
> copy-and-pasteable path to the exexcutable I need. But I
> do not know how to stop the program from the command line.
> Help please.
/*////////////////////////////////////////////////////////////////////
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();
Quote:
}
// --- Collect script arguments (if any):
for (var i=0; i<oArgs.length ; i++) {
// Collect passed arguments
sArgsLine += "\"" + oArgs(i) + "\" ";
sArgsAry[sArgsAry.length] = oArgs(i)
Quote:
}
// --- 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();
Quote:
}
// --- Kill process(es):
for (var i=0; i<sArgsAry.length ; i++) {
WScript.Echo("Killing (if any): " + sArgsAry[i]);
KillProcess(sArgsAry[i]);
Quote:
}
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(); }
Quote:
}
function isCScript() { return (/cscript.exe$/i).test(WScript.FullName); }
// Branimir