473,725 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to stop a process on local machine

I am working on a C# Windows program that needs to kill a known
process. I have written code that works in development mode but hits
an "Access Denied" exception when running the compiled program:

Here's my original code:
// Now stop the server process
Process[] myProcesses;
myProcesses = Process.GetProc essesByName("My Server");
foreach(Process myProcess in myProcesses)
{
myProcess.Kill( );
}

It was suggested that I should use WMI, so I scrapped the above code
and wrote the following code:

ManagementScope ms = new ManagementScope ( @"root\cimv2 " ) ;
string LSProcessName = "'MyServer' ";
string querystring = "Select * from Win32_Process Where Name = " +
LSProcessName ;
ObjectQuery oq = new ObjectQuery ( querystring ) ;
ManagementObjec tSearcher query = new ManagementObjec tSearcher ( ms, oq
) ;
ManagementObjec tCollection querycollection = query.Get( ) ;
foreach ( ManagementObjec t mo in querycollection )
mo.InvokeMethod ("Terminate",nu ll);

This code doesn't stop the process -- as the query doesn't find the
process. Any ideas what I may have wrong here?

Any/all help much appreciated. :?:
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 15 '05 #1
0 1287

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

Similar topics

4
9197
by: John | last post by:
I am trying to spawn a seperate process from my asp page so when a user clicks the link or button a desktop program is launched. This will be on an intranet and the program will exist on the users desktop. I can use the following code in webmatrix to run a process on my local machine: <%@ Page Language="VB" %> <script runat="server"> ' Insert page code here
5
14105
by: toby | last post by:
Can any one help? I'm trying to use System.Diagnostics.Process.Start to open legacy MS access aplications (ade and mdb files) and vb 6 .exe's using asp.net. There is something confusing going on?!? The files are all in the same network location, when I try and start the MSaccess files I get a "file not found" error (it does go as far as opening Msaccess, but doesn't load the DB), when I try to start the exe, the .exe is found and runs, but...
12
2268
by: Vadym Stetsyak | last post by:
Hi there! Is there any way how can I stop garbage collection for a period of time. Lets say, I have a form. Before form load I pause the GC and when the form is shown resume GC
5
5427
by: hangten | last post by:
I have a service that 1) uses filewatcher to watch a directory on a remote machine. 2) checks if a certain application is running on the local machine before starting it. The problem is while checking for an existing instance of the application. I do the following code : Process processes = Process.GetProcessesByName(stProcName, localcpu); Where stProcName is the process I am checking localcpu is the local machine name.
7
6859
by: Denis Brkljacic | last post by:
Hi, I have made some simple ASP.NET (C#) application, that somewhere uses this command: Process aProcesses = Process.GetProcesses(Environment.MachineName); This command purpose is to find some proccess on local machine and do something. This works perfect on the machine (XP) where I have been developing this app!
1
1214
by: Indepth | last post by:
Overview: We're creating a ASP.NET app in C# that calls some C# programs we've created. Our DB server is on a w2k3 machine and using our w2k machines as our web server. Without setting an Identity in the web.config we can not access the DB on the w2k3 machine at all. So a temporary solution we had was to use the w2k3 machine as the DB and Web server but this isn't the setup that has be requested to duplicate. Problem: When we set an...
0
1264
by: martin | last post by:
Hi, I have a website on my local development machine that has a page where a small number of services (that I have wrote myself) can be either started or stopped. The website uses forms authentication at present, so as far as I am aware I can't use windows authetication (not sure if this is relevant or not) At present the virtual directory that is running the application is set to "Anonymous" Accss and is running under the...
11
13412
by: Kirk | last post by:
The following C# web service works fine until you uncomment the lines setting UserName and Password. Then the process starts as the specified user, but hangs in a suspended state. In fact, any executable will exhibit this problem; it is not specific to whoami.exe. This is with .NET 2.0, of course (1.1 does not support running a process as a different user). This appears to be a bug. Can anyone comment? <%@ WebService Language="C#"...
1
3838
by: Daniel | last post by:
what permissions does a windows service need to execute another process? System.Diagnostics.Process process = System.Diagnostics.Process.Start(info); just local administrator? any specific permitions?
0
8752
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
9401
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
9257
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9176
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9113
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
8097
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
6702
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
6011
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();...
1
3221
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

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.