473,513 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GetProcessesByName 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.GetProcessesByName(CProcWatch.PROCNAME);
try
{
foreach (Process pr in proc)
{
if (String.Compare(pr.ProcessName, CProcWatch.PROCNAME, true) ==
0)
pr.Kill();
}
}
catch(Exception e)
{
errlog.Log("CProcWatch", "Error " + e.Message + " occured at: " +
System.DateTime.Now.TimeOfDay.ToString());
}
Thread.Sleep(10000);
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 4908
You can't kill a process owned by another account unless you explicitly
enable the "SeDebugPrivilege" 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.Management and WMI's Win32_Process class to terminate
a process.
Or you have to enable the SeDebugPrivilege by calling Win32 API's
LookupPrivilegeValue and AdjustTokenPrivileges using PInvoke.
Willy.

"Steve Long" <St**********@NoSpam.com> wrote in message
news:eW**************@TK2MSFTNGP10.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.GetProcessesByName(CProcWatch.PROCNAME);
try
{
foreach (Process pr in proc)
{
if (String.Compare(pr.ProcessName, CProcWatch.PROCNAME, true)
==
0)
pr.Kill();
}
}
catch(Exception e)
{
errlog.Log("CProcWatch", "Error " + e.Message + " occured at: " +
System.DateTime.Now.TimeOfDay.ToString());
}
Thread.Sleep(10000);
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****************@tk2msftngp13.phx.gbl...
You can't kill a process owned by another account unless you explicitly
enable the "SeDebugPrivilege" 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.Management and WMI's Win32_Process class to terminate a process.
Or you have to enable the SeDebugPrivilege by calling Win32 API's
LookupPrivilegeValue and AdjustTokenPrivileges using PInvoke.
Willy.

"Steve Long" <St**********@NoSpam.com> wrote in message
news:eW**************@TK2MSFTNGP10.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.GetProcessesByName(CProcWatch.PROCNAME);
try
{
foreach (Process pr in proc)
{
if (String.Compare(pr.ProcessName, CProcWatch.PROCNAME, true)
==
0)
pr.Kill();
}
}
catch(Exception e)
{
errlog.Log("CProcWatch", "Error " + e.Message + " occured at: " +
System.DateTime.Now.TimeOfDay.ToString());
}
Thread.Sleep(10000);
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 AdjustTokenPrivileges. 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****************@tk2msftngp13.phx.gbl...
You can't kill a process owned by another account unless you explicitly
enable the "SeDebugPrivilege" 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.Management and WMI's Win32_Process class to terminate a process.
Or you have to enable the SeDebugPrivilege by calling Win32 API's
LookupPrivilegeValue and AdjustTokenPrivileges using PInvoke.
Willy.

"Steve Long" <St**********@NoSpam.com> wrote in message
news:eW**************@TK2MSFTNGP10.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.GetProcessesByName(CProcWatch.PROCNAME);
try
{
foreach (Process pr in proc)
{
if (String.Compare(pr.ProcessName, CProcWatch.PROCNAME, true)
==
0)
pr.Kill();
}
}
catch(Exception e)
{
errlog.Log("CProcWatch", "Error " + e.Message + " occured at: " +
System.DateTime.Now.TimeOfDay.ToString());
}
Thread.Sleep(10000);
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
994
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...
2
2467
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...
5
5414
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...
5
1473
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 >...
5
2243
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...
4
1679
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...
4
4177
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...
2
19076
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...
2
2409
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...
0
7260
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
7539
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...
1
7101
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
7527
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...
0
5686
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
3234
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...
0
1597
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 ...
1
803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
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...

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.