C
C#2mo ago
M B V R K

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 :
process[0].Kill();
process[0].Kill();
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 <3
GitHub
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
SpReeD
SpReeD2mo ago
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.
M B V R K
M B V R K2mo ago
What the solution then, please ?
Your chance is to run your application with elevated privileges
You means Run as Administrator ?
SpReeD
SpReeD2mo ago
I do
M B V R K
M B V R K2mo ago
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 issue
SpReeD
SpReeD2mo ago
Well, 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.
M B V R K
M B V R K2mo ago
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 ?
SpReeD
SpReeD2mo ago
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.
SpReeD
SpReeD2mo ago
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.2
ManagementEventWatcher Class (System.Management)
Subscribes to temporary event notifications based on a specified event query.
SpReeD
SpReeD2mo ago
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.
M B V R K
M B V R K2mo ago
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