There is a function in pg_service_test.c which checks if the process is running as a service. It was extracted from PostgreSQL code and modified a bit (to add debug outputs). CheckTokenMembership should set isMember to FALSE here (when running as local admin) but it is not.
I think that using NtAccessCheck with some random access mask (or it is not random?) here is not a reliable way to do the check.
Compiled exe file from this code is attached