473,785 Members | 2,651 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("winm gmts:" _
& "{impersonation level=impersona te}!\\"&strcomp uter & "\root\cimv 2")
Set colprocesslist = objwmiservice.e xecquery _
("SELECT * FROM Win32_Process WHERE Name = 'winword.exe'")
For Each objprocess In colprocesslist
objprocess.term inate()
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("winm gmts:{impersona tionlevel=imper sonate}!\\\\" +
strcomputer + "\\root\\cimv2" );
var colitems = objWMIService.E xecQuery("SELEC T * FROM Win32_Process
WHERE Name = 'winword.exe'") ;
var indexitems;
for (indexitems in colitems){
indexitems.Term inate();
}

Thanks for the help.

Jul 23 '05 #1
3 11548
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("winm gmts:{impersona tionlevel=imper sonate}!\\\\" +
strcomputer + "\\root\\cimv2" );
colitems = objWMIService.E xecQuery("SELEC T * FROM Win32_Process WHERE
name = 'winword.exe'") ;
e = new Enumerator(coli tems);
for (; !e.atEnd(); e.moveNext())
{
e.item().Termin ate();
}

Jul 23 '05 #2
ab***********@g mail.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:{impe rsonationlevel= impersonate}!\\ \\" +
strcomputer +
"\\root\\ci mv2"
);
var colitems = new Enumerator(
objWMIService.E xecQuery(
"SELECT * FROM Win32_Process WHERE Name = 'winword.exe'"
)
);
for (; !colitems.atEnd (); colitems.moveNe xt()) {
colitems.item() .Terminate();
}

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

ciao, dhgm
Jul 23 '05 #3


ab***********@g mail.com wrote:

strcomputer = "."
var objWMIService =
GetObject("winm gmts:{impersona tionlevel=imper sonate}!\\\\" +
strcomputer + "\\root\\cimv2" );
var colitems = objWMIService.E xecQuery("SELEC T * FROM Win32_Process
WHERE Name = 'winword.exe'") ;
var indexitems;
for (indexitems in colitems){
indexitems.Term inate();
}


You can do it with an Enumerator:

var computer = '.';
var WMIService = GetObject('winm gmts:' +
'{impersonation Level=impersona te}!\\\\' +
computer + '\\root\\cimv2' );
var processList = WMIService.Exec Query('Select * From Win32_Process') ;
WScript.Echo('F ound ' + processList.Cou nt + ' processes.');
var processEnumerat or = new Enumerator(proc essList);
while (!processEnumer ator.atEnd()) {
WScript.Echo(pr ocessEnumerator .item().Name);
processEnumerat or.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
17722
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
21032
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 application properly which results in the Phone Dialer icon remaining in the system tray. I've tried using the Windows API to refresh the system tray, but could not get that to work. How to I gracefully close the phone dialer application with...
7
5758
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 so, where is the information on the event the would be raised located in the .NET framework? Thanks in advance for your help and information.
3
13786
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
5923
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 Information using the WMI Win32_process
2
7084
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 the service can't retrieve the commandline property of the processes. I think this is an result of .NET Framework 1.1 Service Pack 1 or XP SP2. Did somebody recognice the same effect? Did anybody knows how i can retrieve the commandline property...
2
2506
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 = Win32::Process::List->new(); print "Enter the process name.exe to terminate: ";
0
1693
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 the process name in the local system... use Win32::Process::List; use Win32::OLE;
1
2462
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
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10315
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.