How can I do that? it needs to check it by the exact path, not by the name. Thanks for your help.
|
.NET
check if process is already running |
|
U can use NtQueryInformationProcess w/ the ProcessImageFileName class. This will let you get the file name for any process you have sufficient access to and not just your own. See msdn for more infos.
Code Declare Function NtQueryInformationProcess Lib "ntdll.dll" ( _If you're trying to do this for your own process, then you can access the PEB and use the process parameter information ProcessParameters (_RTL_USER_PROCESS_PARAMETERS*) field. Code typedef struct _RTL_USER_PROCESS_PARAMETERS {The structure syntax is in C and not VB.NET. You'll have to convert it yourself appropriately. The ImagePathName field of the structure will have a Buffer field since its a _UNICODE_STRING and that will contain the proper file name of the image for the process. If you really need to do it from .NET APIs then you can but you'll learn something new if you do it manually like above. Which will season your dev skills.
Oct 1, 2018 02:54 AM
(This post was last modified: Oct 1, 2018 03:13 AM by Washi.)
(Sep 29, 2018 01:09 PM)oxidebuffalo Wrote: -snip- I mean you could do that, but you can also just go the .NET route and obtain the path using ProcessModule.FileName on the mainmodule (Process.MainModule) of the processes with the same name as the current process. Sure you would learn something new if you do it manually, but other than that, not sure what benefits it really has. PHP Code
https://github.com/Washi1337
"I'll tell you this UDP joke, and I don't care if you will get it or not." (Oct 1, 2018 02:54 AM)Washi Wrote: I mean you could do that, but you can also just go the .NET route and obtain the path using ProcessModule.FileName on the mainmodule (Process.MainModule) of the processes with the same name as the current process. Sure you would learn something new if you do it manually, but other than that, not sure what benefits it really has. You will get access denied if you try to access 64-bit processes with a 32-bit app when accessing Process.MainModule and there's no way around it on .net , even if you run a 64-bit app you will get access denied for PID 4 (System) and PID 0 (idle) , the best way is probably querying the winapi directly or WMI, https://stackoverflow.com/a/3654195
Oct 1, 2018 12:44 PM
(This post was last modified: Oct 1, 2018 12:46 PM by Washi.)
(Oct 1, 2018 12:24 PM)He B TeMy Wrote: You will get access denied if you try to access 64-bit processes with a 32-bit app when accessing Process.MainModule and there's no way around it on .net , even if you run a 64-bit app you will get access denied for PID 4 (System) and PID 0 (idle) , the best way is probably querying the winapi directly or WMI, https://stackoverflow.com/a/3654195 I guess that is true, but then again, you are checking for processes that are running your application. If your application is 32 bit, then you will be opening 32 bit processes as well, and 64 bit processes otherwise. It would only fail when you share a process name with another application. I guess better safe than sorry though. You could maybe wrap the retrieval of the file path in a try-catch statement. An exception can only be caught when the platforms mismatch, which already gives away the fact that the process you're trying to open is not the same application.
https://github.com/Washi1337
"I'll tell you this UDP joke, and I don't care if you will get it or not." (Oct 1, 2018 12:24 PM)He B TeMy Wrote: even if you run a 64-bit app you will get access denied for PID 4 (System) and PID 0 (idle)You're always going to get STATUS_ACCESS_DENIED (NTSTATUS error code) returned from NtOpenProcess whilst trying to open a handle to a process like the "System" process. The "System" process (PID of 4 reserved for it nowadays) is for ntoskrnl.exe. |
|
|



