maccten2000
Programmer
Hi All,
I have the following function which I put together by skimming this very helpful folders. Basically from my understanding is the function creates a vbs script and kills the last Excel process which is perfect for my needs. My problem is it doesn't seem to activate the script on the PC. I was wondering if someone could look at the code below and offer any pointers. Thanks for your time
I have the following function which I put together by skimming this very helpful folders. Basically from my understanding is the function creates a vbs script and kills the last Excel process which is perfect for my needs. My problem is it doesn't seem to activate the script on the PC. I was wondering if someone could look at the code below and offer any pointers. Thanks for your time
Code:
var wsh = new JOOLEObject("WScript.Network");
var user = wsh.UserName;
strkillExcelfile = "C:\\Documents and Settings\\" + user + \\My Documents\\Brio Reports\\KillExcel.vbs
function killExcel(strkillExcelfile){
try{
// Defining vbs filename and destination
// creating file system JooleObject
var oScripting = new JOOLEObject("Scripting.FileSystemObject" );
// creating text file to receive vbs scripting
var oVBSFile = oScripting.CreateTextFile(strkillExcelfile);
// defining string with the vbs code
var sVbScript = "strComputer = \".\"\r\nSet objWMIService = GetObject(\"winmgmts:{impersonationLevel=impe rsonate}!\\\\\" & strComputer & \"\\root\\cimv2\")\r\nSet colProcessList = objWMIService.ExecQuery (\"Select * from Win32_Process Where Name = \'EXCEL.EXE\'\")\r\nDim Counter\r\nCounter = 0\r\nFor Each objProcess in colProcessList\r\nCounter = Counter + 1\r\nif Counter = colProcessList.count Then\r\nobjProcess.Terminate()\r\nEnd if\r\nNext";
// writing vbs code to text file and saving as vbs file
oVBSFile.WriteLine(sVbScript);
// closing file
oVBSFile.Close();
Console.Writeln(strkillExcelfile)
// executing file
Application.Shell(strkillExcelfile);
}
catch(e)
{
throw e.toString();
}
}
fKillExcel = killExcel
fKillExcel (strkillExcelfile)