473,804 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Process.GetProc essesByName

9 New Member
hello,

can anyone tell what the hell is the problem with my program...?
i built a program that getting all the process from windows by the name of "excel", when i compile it and creating a .exe file and start it on my comp, it's working perfectly, but when i tried to run it on en other computer it stops working with out telling me what exception throwed, but just telling that the program has to close and they are sorry for the inconvenience.
what the hell is worng, Please somone help me.....!
the code is:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Diagnostics;
  6.  
  7. namespace ConsoleApplication2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {            
  13.             Process[] excelProcess = Process.GetProcessesByName("EXCEL");
  14.             foreach (Process p in excelProcess)
  15.             {
  16.                 p.Kill();
  17.             }
  18.         }
  19.     }
  20. }
Nov 30 '08 #1
2 2620
tlhintoq
3,525 Recognized Expert Specialist
You might want to flesh out the application a little so *it* can tell you what it is doing and thus you should be able to find the problem.

Add a dialog box that lists all the matching processes it found.
Add a [yes/no] routine so that all processes that match will throw up a dialog asking if you want it killed.
Write a log file recording all the processes, and all the processes that match, and all the processes killed. See if you can find a cause/pattern.

Those types of things should give you some information to go on.

BTW: You didn't mention the name of the compiled application. If you called it "Excel Killer" for example it would *be* a process that would qualify for killing.

I notice that you have using System.Linq; directive but no use of .NET 3.5 is this little example. Are you sure that your target machine has .NET 3.5 installed? Try commenting-out that directive and see what happens.
Dec 1 '08 #2
Plater
7,872 Recognized Expert Expert
Some try/catch action would help you as well.
None of that code is garunteed.
p.Kill() could be rejected for permissions issues too
Dec 1 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1060
by: Henrik | last post by:
Hi, I would like to take a process object and turn it into an instance of a com-object somehow. I know that I can get all Microsoft Word processes running by using Process.GetProcessesByName("winword") which I can't put into a word application object. I also know that I can get one (without being able to specify which) of those running processes by using GetObject(Class:="Word.Application") which I
5
5435
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.
3
5811
by: DAMAR | last post by:
Hello Is it possible to know when a particular process started? For example: I have such situation: I need to know when a notepad.exe is started - i need to get an event of starting this process. Can anyone help me?
1
8494
by: Max | last post by:
I'm trying to get the process id of some application and I get an error for this line: Process myApplications= Process.GetProcessesByName("MyApplication"); The error says: System.InvalidOperationException: Process performance counter is disabled, so the requested operation cannot be performed. at System.Diagnostics.NtProcessManager.GetProcessInfos(PerformanceCounterLib library) at...
9
21658
by: DraguVaso | last post by:
Hi, I want my application to bring another application to the Front. I thought best way to do this was by the Process-model: Dim c As Process = Process.GetCurrentProcess() Dim p As Process For Each p In Process.GetProcessesByName("EXTRA") If Left(p.MainWindowTitle, 4) = "Appl" Then 'Here I should be able to Bring the Process to the Front!!!
3
1280
by: Nikolay Petrov | last post by:
I have a class which starts a process and redirects it's output and input. My class have a method which starts the process and another which stops it. How can I check if the process have been already started, so I don't try to start it again, and how to check if the process is not running so i don't try to stop again? code: Public Class ProcEx Private p As Process Public Sub StartProcess()
5
1778
by: kd | last post by:
Hi All, If the name of a process is known, is it possible to check whether it is in execution? What I did was to fetch all the processes running on the system using Process.GetProcesses() and traverse through the array looking for the Process name. Is there a shortcut or easier way to accomplish this?
2
19106
by: kd | last post by:
Hi All, Process.GetProcessesByName() is not giving the expected results. Here is a sample code. Dim TestProcess() As Process Try TestProcess= Process.GetProcessesByName("Test.exe") If TestProcess.Length = 0 Then MsgBox("Not running", MsgBoxStyle.OKOnly)
4
1620
by: Miro | last post by:
I'm using VB.Net 2003 I have code - it works great - to kill a process(s) if they are running. ---- Dim myProcesses() As Process 'Funny - withouth the () in the myProcesses it does not work Dim myProcess As Process myProcesses = Process.GetProcessesByName(Trim(TextBox1.Text)) For Each myProcess In myProcesses
7
2704
by: sravan_reddy001 | last post by:
I want to handle a running process. ex: explorer.exe How can i handle that process(explorer.exe). and is it possilbe to stop that process from runing.
0
9714
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
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
10599
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
10346
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
10347
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
10090
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
9173
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...
0
6863
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
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.