473,395 Members | 1,987 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,395 software developers and data experts.

Win32Exception while getting a process handle?!

Tim
Hey guys,
I tried to get a process handle with the following code snippet:

00 Process[] processes = Process.GetProcesses();
01 if (null != processes && processes.Length 0)
02 {
03 foreach (Process currentProcess in processes)
04 {
05 if (null != currentProcess)
06 {
07 if (currentProcess.Handle !=
Process.GetCurrentProcess().Handle)
08 {
09 if
(currentProcess.MainModule.FileName.ToLower().Cont ains("processname"))
10 {
11 currentProcess.Kill();
12 }
13 }
14 }
15 }
16 }

As soon as I reach line XX the framework will throw a Win32Exception
with the exception message "Access denied". The application should
have all needed user privileges because it runs as a service
application with the SYSTEM account permissions. As of this, I think
that my application will need additional .NET rights. Has somebody any
idea how to get the required permission? Thanks a lot.

Best regards,
Tim
Dec 11 '07 #1
2 6513
Tim
It should be line "07" and not line "XX" ;)
Dec 11 '07 #2
What is Process.ProcessName for the process you are trying to retrieve the
handle for?

If it's a system process, you'll be unlikely to have been granted all access
to open the process. When Process gets the handle it tries to open the
process with PROCESS_ALL_ACCESS, if you've been denied any process permission
for that particular process you will get an access denied error (via
Win32Exception).

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
"Tim" wrote:
Hey guys,
I tried to get a process handle with the following code snippet:

00 Process[] processes = Process.GetProcesses();
01 if (null != processes && processes.Length 0)
02 {
03 foreach (Process currentProcess in processes)
04 {
05 if (null != currentProcess)
06 {
07 if (currentProcess.Handle !=
Process.GetCurrentProcess().Handle)
08 {
09 if
(currentProcess.MainModule.FileName.ToLower().Cont ains("processname"))
10 {
11 currentProcess.Kill();
12 }
13 }
14 }
15 }
16 }

As soon as I reach line XX the framework will throw a Win32Exception
with the exception message "Access denied". The application should
have all needed user privileges because it runs as a service
application with the SYSTEM account permissions. As of this, I think
that my application will need additional .NET rights. Has somebody any
idea how to get the required permission? Thanks a lot.

Best regards,
Tim
Dec 12 '07 #3

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

Similar topics

1
by: Patrick Dugan | last post by:
Is it possible to get the handle of a running service? I have a program (ActiveX program) running in memory. When I start my service I need to pass the service's handle to that program in order...
6
by: Leonel Galán | last post by:
When doing Process.Start(), I get "The parameter is invalid" Win32Exception when opening a particular exe. This exe works good in Windows (cmd.exe). The exe is "SPIM.exe" as the Simulator for...
1
by: nhmark64 | last post by:
Hi, Sometimes when I execute this.Opacity = 0; in the Main thread I get the below exception: System.ComponentModel.Win32Exception was unhandled by user code Message="Not enough storage is...
0
by: =?Utf-8?B?TWFyaw==?= | last post by:
Users of an in-house application we have written randomly get an Error creating window handle exception, and we've not been able to determine why this happens. A typical callstack is as follows: ...
5
by: Atara | last post by:
On Windows Vista, Process.Start() generates Win32Exception. Sample Code: Dim selfProc As String = System.Windows.Forms.Application.ExecutablePath System.Diagnostics.Process.Start(Chr(34) &...
7
by: =?Utf-8?B?ams=?= | last post by:
I am using System.Diagnostics.Process class to open a word document by call ing Process.Start("test.doc"). I am using C# as programming language. On some of the computers on running this code i get...
1
by: ranju | last post by:
I am trying to spawn a process (say an exe file) with different user crendentials than that of the current user. 1) Called LogonUserEx() to logon the user and recieve a handle to the token that...
33
by: JamesB | last post by:
I am writing a service that monitors when a particular app is started. Works, but I need to get the user who is currently logged in, and of course Environment.UserName returns the service logon...
1
by: desivirus | last post by:
hi admin.. i followed your tip in "HOW TO LIST PROCESS ID IN WINDOWS" thread..and iam trying to compile this code in cygwin , $gcc -mno-cygwin process.c -o -L"psapi.lib" process.exe psapi.h...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
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...

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.