473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

terminate named Win32_Process

Hi,
How to make javascript terminate a win32_process?

vbscript will terminate a named process with the following code:

strcomputer = "."
Set objwmiservice = GetObject("winmgmts:" _
& "{impersonationlevel=impersonate}!\\"&strcompu ter & "\root\cimv2")
Set colprocesslist = objwmiservice.execquery _
("SELECT * FROM Win32_Process WHERE Name = 'winword.exe'")
For Each objprocess In colprocesslist
objprocess.terminate()
next

javascript: Here is my best attempt at translating the vbscript into
javascript, but javascript just closes with no error message without
killing the process.

strcomputer = "."
var objWMIService =
GetObject("winmgmts:{impersonationlevel=impersonat e}!\\\\" +
strcomputer + "\\root\\cimv2");
var colitems = objWMIService.ExecQuery("SELECT * FROM Win32_Process
WHERE Name = 'winword.exe'");
var indexitems;
for (indexitems in colitems){
indexitems.Terminate();
}

Thanks for the help.

Jul 23 '05 #1
3 11525
I had been searching for the answere all weekend and then I found it
just after posting the question. The answer is the following code. I
was missing enumeration when accessing a collection.

strcomputer = "."
var objWMIService, colitems, e
objWMIService =
GetObject("winmgmts:{impersonationlevel=impersonat e}!\\\\" +
strcomputer + "\\root\\cimv2");
colitems = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE
name = 'winword.exe'");
e = new Enumerator(colitems);
for (; !e.atEnd(); e.moveNext())
{
e.item().Terminate();
}

Jul 23 '05 #2
ab***********@gmail.com wrote:
vbscript will terminate a named process with the following code: [...]
javascript: Here is my best attempt at translating the vbscript into
javascript, but javascript just closes with no error message without
killing the process.


JavaScript's for..in does not work as you expect on VB-like collections.
An Enumerator object [1] is your friend:

var strcomputer = "."
var objWMIService = GetObject(
"winmgmts:{impersonationlevel=impersonate}!\\\ \" +
strcomputer +
"\\root\\cimv2"
);
var colitems = new Enumerator(
objWMIService.ExecQuery(
"SELECT * FROM Win32_Process WHERE Name = 'winword.exe'"
)
);
for (; !colitems.atEnd(); colitems.moveNext()) {
colitems.item().Terminate();
}

[1] http://msdn.microsoft.com/library/en...enumerator.asp

ciao, dhgm
Jul 23 '05 #3


ab***********@gmail.com wrote:

strcomputer = "."
var objWMIService =
GetObject("winmgmts:{impersonationlevel=impersonat e}!\\\\" +
strcomputer + "\\root\\cimv2");
var colitems = objWMIService.ExecQuery("SELECT * FROM Win32_Process
WHERE Name = 'winword.exe'");
var indexitems;
for (indexitems in colitems){
indexitems.Terminate();
}


You can do it with an Enumerator:

var computer = '.';
var WMIService = GetObject('winmgmts:' +
'{impersonationLevel=impersonate}!\\\\' +
computer + '\\root\\cimv2');
var processList = WMIService.ExecQuery('Select * From Win32_Process');
WScript.Echo('Found ' + processList.Count + ' processes.');
var processEnumerator = new Enumerator(processList);
while (!processEnumerator.atEnd()) {
WScript.Echo(processEnumerator.item().Name);
processEnumerator.moveNext();
}

Note that you would better ask such questions in a WSH oder server
scripting group on the MS news server.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: x-herbert | last post by:
Hi, I have a small test to "compile" al litle script as a WMI-Tester. The script include a wmi-wrapper and "insert" the Win32-modeles. here the code: my "WMI-Tester.py" ----- import wmi
4
by: deko | last post by:
I use the default windows phone dialer to make calls from an Access form. I close the phone dialer after the call is made using the below function. The problem is I'm not closing the Phone Dialer...
7
by: Andrew S. Giles | last post by:
Hello, I am looking for an article, or some information about how to get a C# windows forms application to trap the "End Process" event from the Task Manager? Is such a thing possible, and if...
3
by: Keith Grefski | last post by:
I cant seem to figure out how to terminate a process in vb.net i can do it using vbscript and wmi but terminate doesnt seem to exist in the available classes for wmi under vb.net
3
by: Peter Neuburger via .NET 247 | last post by:
(Type your message here) -------------------------------- From: Peter Neuburger Hi Everybody, I need some help with the WMI Terminate Method. I have a Listbox where I get all the Process...
2
by: Christoph Borger | last post by:
Hello! I have wrote a windows service in vb.net. This service monitors the running processes with WMI and the Win32_Process class. Till last month all seems ok. But since the begin of september...
2
by: cnsabar | last post by:
Hi., I am using the following code to terminate the any process by giving the process name as input... use Win32::Process::List; use Win32::OLE; $Win32::OLE::Warn = 3; $P =...
0
by: cnsabar | last post by:
Hi., I need a Perl script to terminate the any running process in server. by specifying computer name and process name.. I have the following code to terminate the any process by specifying...
1
by: thunder54007 | last post by:
hi, here is my script: import win32con import time import wmi c = wmi.WMI() for process in c.Win32_Process(name = "notepad.exe"): print process.ProcessId, process.Name process.Terminate ()
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.