Page 1 of 1

#THREAD_ALL_ACCESS correct in PB?

Posted: Sun Jul 19, 2009 12:48 pm
by SFSxOI
In the MSDN at > http://msdn.microsoft.com/en-us/library ... S.85).aspx

It says this for THREAD_ALL_ACCESS:

"Windows Server 2003 and Windows XP/2000: The size of the THREAD_ALL_ACCESS flag increased on Windows Server 2008 and Windows Vista. If an application compiled for Windows Server 2008 and Windows Vista is run on Windows Server 2003 or Windows XP/2000, the THREAD_ALL_ACCESS flag is too large and the function specifying this flag fails with ERROR_ACCESS_DENIED. To avoid this problem, specify the minimum set of access rights required for the operation. If THREAD_ALL_ACCESS must be used, set _WIN32_WINNT to the minimum operating system targeted by your application (for example,
#define _WIN32_WINNT _WIN32_WINNT_WINXP
). For more information, see Using the Windows Headers. "

So...refering to the WinNT.h in the latest SDK, I find this:

Code: Select all

#if (NTDDI_VERSION >= NTDDI_LONGHORN)
#define PROCESS_ALL_ACCESS        (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \ 0xFFFF)
#else
#define PROCESS_ALL_ACCESS        (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \ 0xFFF)
where:

0xFFFF = 65535 (this is NTDDI_LONGHORN = Vista - Win 7 - Server 2008)
0xFFF = 4095 (this is all others not Vista or Win 7 or Server 2008)

So for Vista - Windows 7 - Server 2008 #PROCESS_ALL_ACCESS should be:

Code: Select all

Debug #STANDARD_RIGHTS_REQUIRED | #SYNCHRONIZE | 65535

= 2097151
And for all other versions of windows (i.e... XP and below) it should be this:

Code: Select all

Debug #STANDARD_RIGHTS_REQUIRED | #SYNCHRONIZE | 4095

= 2035711 (which is $1F0FFF) which is the PureBasic value for #PROCESS_ALL_ACCESS 

The constant in Purebasic has this value:

#PROCESS_ALL_ACCESS = 2035711 (which is $1F0FFF)

So the constant in PureBasic is not valid for use with Vista -Windows 7 - Server 2008 ???

Posted: Sun Jul 19, 2009 3:12 pm
by freak
Well, the constant is quite useless if it causes failure on all systems < Vista, which is why the old constant is still used. (There was a bugreport about this issue too). It is also valid for Vista, it just specifies a few less access rights (the Vista specific ones are missing).

But using the ..._ALL_ACCESS flags is usually not a good idea anyway, as then the function may fail because you are missing some rights which you do not need anyway. Instead only query the rights you actually need and you won't have this problem.

Posted: Sun Jul 19, 2009 4:31 pm
by SFSxOI
Well, i'm using the flag for a specific purpose program for which i know I already have the rights for in XP, Vista, and Win 7, and these rights are needed.

What bought this to my attention is that when I ran the program on Vista and Win 7 I had this unexplained crash, but on XP it worked without any crash.

When I started looking around I came across this and once I used #PROCESS_ALL_ACCESS_VISTA_WIN7 = $1FFFFF instead of the PB constant of #PROCESS_ALL_ACCESS there were no more crashes in Vista or Win 7 but then when run in XP there was a crash now where as there was none before. So the crash problem seemed to follow the constant.

So what I ended up doing was using both, the constant I established (#PROCESS_ALL_ACCESS_VISTA_WIN7 = $1FFFFF) and the one from PB (#PROCESS_ALL_ACCESS), and then selectively applying them according to which OS the program was running in. After doing that there are no more crashes.

I was using the constants like this in some code that sets thread priority for something i'm working on:

Code: Select all


; Vista & Win 7:

If osversion$ = "Windows Vista"
  hA.i = OpenProcess_(#PROCESS_ALL_ACCESS_VISTA_WIN7,#False,PID) 
EndIf
  
  If osversion$ = "Windows 7"
  hA.i = OpenProcess_(#PROCESS_ALL_ACCESS_VISTA_WIN7,#False,PID)
  EndIf
  
; Win XP:
 
  If osversion$ = "Windows XP"
  hA.i = OpenProcess_(#PROCESS_ALL_ACCESS,#False,PID)
  EndIf

Once the proper constant is used based upon the operating system everything is stable with no crashes and everything works perfectly.