System.ComponentModel.Win32Exception: 'Access is denied'
Hi guys, hope you're all doing well
I'm working on a project, which needs to
start
and kill
some proccesses,
the issue is an excception
always thrown when try to kill processes, and the exception always said :
System.ComponentModel.Win32Exception: 'Access is denied'This is the file I have issue in : https://github.com/MbarkT3STO/OfficeDRPC/blob/main/OfficeDRPCCommander/Worker.cs The exception always happens in this part : All the apps including the app which contains the issue are
Console
targetting .NET Framework 4.7.2
Please any help or solution for this issue ?
Massive thanks in advance, with all love and respect <3GitHub
OfficeDRPC/OfficeDRPCCommander/Worker.cs at main · MbarkT3STO/Offic...
Open-source project to show Discord Rich Presence Activities for most of Microsoft 365/Office apps - MbarkT3STO/OfficeDRPC
10 Replies
As the excpetion says
Access denied
, meaning whoever starts your application don't have the permission to kill the other application. Your chance is to run your application with elevated privileges.What the solution then, please ?
Your chance is to run your application with elevated privilegesYou means
Run as Administrator
?I do
I did it for the
.exe
of the app but still the same issue also I run the Visual Studio
as Administrator
but the same issueWell, are you trying to kill a
Windows Service
ran by local system account
?
Next question, why are you trying to kill
your own process?
It would be better to use an IPC to communicate with your very own processes or implement a Watcher
inside each DRPC.
On the other hand, use a real Worker
or Service
template instead of a console application.I try to kill my services when there is no need to use them, and for realeasing/free up thier holded resources (RAM, CPU)
Daaaaamn, I remember somthing, I have
COMODO Firewall
on my pc and I set my DRPC
apps as Windows applications
, is there could be a cause of the issue ?I'm not familiar with COMODO, but inter-process-communication lets you communicate programmatically with your application/processes, so you could send a shutdown command and the application could exit in a normal manner, instead being killed from the outside.
This could also be achieved by using a
Watcher
inside each DRPC, for instance, in ExcelDRPC, if excel not running Environment.Exit(0)
.
Besides this, your project could be a single Windows Service
monitoring all of the Applications you want; also it would be easier to determine if there's already another application, of your monitored applications, opened and sent to discord.Monitoring processes on
Windows
OS, can be done either through Timers
or using WMI
and the specific built-in classes like ManagementEventWatcher
. See: https://learn.microsoft.com/en-US/dotnet/api/system.management.managementeventwatcher?view=netframework-4.7.2ManagementEventWatcher Class (System.Management)
Subscribes to temporary event notifications based on a specified event query.
The specific
WQL
would be something like
ManagementEventWatcher(new WqlEventQuery("SELECT * FROM Win32_ProcessStartTrace"))
and
ManagementEventWatcher(new WqlEventQuery("SELECT * FROM Win32_ProcessStopTrace"))
for a process being started and stopped.Massive thanks I really appreciate your time and help,
I don't even knowwhy I didn't make them work as a single app
that looks a good idea