Other than running this routine in a cmd window with administrator mode are there any other requirements to use this routine?
Basically, I have two programs. One which I know little about returns the complete argument list of an external program in a cmdLine variable. The second returns null with a System Code of 5 for "Access is denied" which comes from making the OpenProcess routine call in the CProcessHelper::GetProcessCommandLin routine.
I used the first program to learn how to run the routine. The routine is to reside in the second program.
The first program is a service.
The code in the two programs appears to be identical.
System Error Codes:
https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
OpenProcess function (processthreadsapi.h)
To open a handle to another local process and obtain full access rights, you must enable the
SeDebugPrivilege privilege. For more information, see Changing Privileges in a Token.
https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-openprocess
In my first program, I can't find SeDebugPrivilege anywhere.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
You can change the privileges in either a primary or an impersonation token in two ways:
• Enable or disable privileges by using the AdjustTokenPrivileges function.
• Restrict or remove privileges by using the CreateRestrictedToken function.
https://docs.microsoft.com/en-us/windows/win32/secbp/changing-privileges-in-a-token
I've found AdjustTokenPrivileges() in my first program.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Here is some information:
https://stackoverflow.com/questions/8898133/how-to-use-openprocesstoken-adjusttokenprivileges-and-getexitcodeprocess-in-vc
I tried both code segments toward the bottom on that page without success. Do you have any ideas?
The initial problem description and it's solution had a "tp" variable which I couldn't get to compile. It's not explicitly defined.
This is information about "tp". It's the third argument to AdjustTokenPrivileges():
https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-token_privileges
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
UPDATE: I found out how to set AdjustTokenPrivileges(...) and can now retrieve the argument list of other executables. When I call OpenProcess(), it no longer returns "System Error Code" 5 indicating access is denied.
Thank you