473,378 Members | 1,594 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 4878
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
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
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
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
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
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
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
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
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
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.