473,543 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GetProcessesByN ame and Permissions

Hello,
I'm using the Process class to get all the current running processes on my
machine and looking for a particular process. If I find the process, I want
to kill it. However, I've recently started recieving and exception "Error
Access is denied" when I try to kill this process. However, I can open up
Task Manager and kill the process. I'm running my program under my user name
so I don't get why I can kill it in Task Manager but my program can't kill
the process. Below is the code I'm utilizing:

for(;;)
{
proc = Process.GetProc essesByName(CPr ocWatch.PROCNAM E);
try
{
foreach (Process pr in proc)
{
if (String.Compare (pr.ProcessName , CProcWatch.PROC NAME, true) ==
0)
pr.Kill();
}
}
catch(Exception e)
{
errlog.Log("CPr ocWatch", "Error " + e.Message + " occured at: " +
System.DateTime .Now.TimeOfDay. ToString());
}
Thread.Sleep(10 000);
proc = null;
}

Can anybody tell me why I should be getting the Access denied Exception?
Any help would be much appreciate. Thanks

Steve
Nov 16 '05 #1
3 4910
You can't kill a process owned by another account unless you explicitly
enable the "SeDebugPrivile ge" privilege for the calling process (that's what
Taskman does).
Note that caller needs the "Debug programs" account policy enabled (see
local policy - user right assignment).
You can use the System.Manageme nt and WMI's Win32_Process class to terminate
a process.
Or you have to enable the SeDebugPrivileg e by calling Win32 API's
LookupPrivilege Value and AdjustTokenPriv ileges using PInvoke.
Willy.

"Steve Long" <St**********@N oSpam.com> wrote in message
news:eW******** ******@TK2MSFTN GP10.phx.gbl...
Hello,
I'm using the Process class to get all the current running processes on my
machine and looking for a particular process. If I find the process, I
want
to kill it. However, I've recently started recieving and exception "Error
Access is denied" when I try to kill this process. However, I can open up
Task Manager and kill the process. I'm running my program under my user
name
so I don't get why I can kill it in Task Manager but my program can't kill
the process. Below is the code I'm utilizing:

for(;;)
{
proc = Process.GetProc essesByName(CPr ocWatch.PROCNAM E);
try
{
foreach (Process pr in proc)
{
if (String.Compare (pr.ProcessName , CProcWatch.PROC NAME, true)
==
0)
pr.Kill();
}
}
catch(Exception e)
{
errlog.Log("CPr ocWatch", "Error " + e.Message + " occured at: " +
System.DateTime .Now.TimeOfDay. ToString());
}
Thread.Sleep(10 000);
proc = null;
}

Can anybody tell me why I should be getting the Access denied Exception?
Any help would be much appreciate. Thanks

Steve

Nov 16 '05 #2
I'm working on it. Thanks for your reply and I will post again once I can
get it working or if I have another question.

Steve

"Willy Denoyette [MVP]" <wi************ *@pandora.be> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
You can't kill a process owned by another account unless you explicitly
enable the "SeDebugPrivile ge" privilege for the calling process (that's what Taskman does).
Note that caller needs the "Debug programs" account policy enabled (see
local policy - user right assignment).
You can use the System.Manageme nt and WMI's Win32_Process class to terminate a process.
Or you have to enable the SeDebugPrivileg e by calling Win32 API's
LookupPrivilege Value and AdjustTokenPriv ileges using PInvoke.
Willy.

"Steve Long" <St**********@N oSpam.com> wrote in message
news:eW******** ******@TK2MSFTN GP10.phx.gbl...
Hello,
I'm using the Process class to get all the current running processes on my machine and looking for a particular process. If I find the process, I
want
to kill it. However, I've recently started recieving and exception "Error Access is denied" when I try to kill this process. However, I can open up Task Manager and kill the process. I'm running my program under my user
name
so I don't get why I can kill it in Task Manager but my program can't kill the process. Below is the code I'm utilizing:

for(;;)
{
proc = Process.GetProc essesByName(CPr ocWatch.PROCNAM E);
try
{
foreach (Process pr in proc)
{
if (String.Compare (pr.ProcessName , CProcWatch.PROC NAME, true)
==
0)
pr.Kill();
}
}
catch(Exception e)
{
errlog.Log("CPr ocWatch", "Error " + e.Message + " occured at: " +
System.DateTime .Now.TimeOfDay. ToString());
}
Thread.Sleep(10 000);
proc = null;
}

Can anybody tell me why I should be getting the Access denied Exception?
Any help would be much appreciate. Thanks

Steve


Nov 16 '05 #3
Willy, thanks much. I believe I have solved this little problem using
PInvoke with AdjustTokenPriv ileges. At this point, I can adjust the token
privileges but I have to wait until that process runs again to see if that
cures the problem.
Thanks again.

Steve

"Willy Denoyette [MVP]" <wi************ *@pandora.be> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
You can't kill a process owned by another account unless you explicitly
enable the "SeDebugPrivile ge" privilege for the calling process (that's what Taskman does).
Note that caller needs the "Debug programs" account policy enabled (see
local policy - user right assignment).
You can use the System.Manageme nt and WMI's Win32_Process class to terminate a process.
Or you have to enable the SeDebugPrivileg e by calling Win32 API's
LookupPrivilege Value and AdjustTokenPriv ileges using PInvoke.
Willy.

"Steve Long" <St**********@N oSpam.com> wrote in message
news:eW******** ******@TK2MSFTN GP10.phx.gbl...
Hello,
I'm using the Process class to get all the current running processes on my machine and looking for a particular process. If I find the process, I
want
to kill it. However, I've recently started recieving and exception "Error Access is denied" when I try to kill this process. However, I can open up Task Manager and kill the process. I'm running my program under my user
name
so I don't get why I can kill it in Task Manager but my program can't kill the process. Below is the code I'm utilizing:

for(;;)
{
proc = Process.GetProc essesByName(CPr ocWatch.PROCNAM E);
try
{
foreach (Process pr in proc)
{
if (String.Compare (pr.ProcessName , CProcWatch.PROC NAME, true)
==
0)
pr.Kill();
}
}
catch(Exception e)
{
errlog.Log("CPr ocWatch", "Error " + e.Message + " occured at: " +
System.DateTime .Now.TimeOfDay. ToString());
}
Thread.Sleep(10 000);
proc = null;
}

Can anybody tell me why I should be getting the Access denied Exception?
Any help would be much appreciate. Thanks

Steve


Nov 16 '05 #4

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

Similar topics

0
996
by: Peter Stojkovic | last post by:
I call GetProcessesByName( myApplictaionName) to test wether an old application-instance of my software is running. Then always my disk-drive runs a short time The program and everything is started from c:
2
2472
by: Hans | last post by:
I am using Process.GetProcessesByName("SomeName") in my app and it workes on most windows platforms. On most - it does not work in a terminal server session on a Windows 2003 server. Although the app is strong named and the server has a code group with full access, Process.GetProcessesByName() throws a security exception. Can anybody tell...
5
5416
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);...
5
1475
by: Lord Fonty | last post by:
Hi All I posted this recently and no one responded so I am wondering if there are any guru's out there whould could help me: > I keep getting the above message when using > GetProcessesByName(ProcessName,this.IPAddress) > > Does anyone know why?
5
2247
by: Andy | last post by:
Hi all, Just started having a problem with this. It seems now that GetProcessesByName will block for about 10-15 seconds before returning. It never happened before, this is a recent development. I'm NOT trying to prevent another instance of my program from starting, so those solutions aren't applicable to my problem. I've also read...
4
1680
by: JZ | last post by:
Hi, Has anyone else got this? I've downloaded the IT Professional network version of XP SP2 to test my programs. I found a problem with GetProcessesByName it just seems to hang. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
4
4179
by: Samuel R. Neff | last post by:
Most of the time what I've read is that to keep only one instance of an app running one should use a Mutex. However, we have an existing app that uses GetProcessByName() to ensure only one instance is running. What are the advantages of a Mutex besides protecting against name collision (which I imagine can be high since GetProcessesByName...
2
19078
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)
2
2414
by: Dave | last post by:
Hi - I have an application that is monitoring a process on another machine. This application runs as a service. The error that I am getting when this runs is: Couldn't get process information from remote machine. System.ComponentModel.Win32Exception: Access is denied I have searched the web extensively to solve my problem, but have...
0
7411
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...
0
7354
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...
1
7354
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...
0
5888
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...
1
5282
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...
0
3394
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1824
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
1
978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
643
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...

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.