Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Kill Excel Object Brio 6

Status
Not open for further replies.

maccten2000

Programmer
May 13, 2003
37
EU
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

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)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top