Hello All,
We have the following code snippet:
Dim hToken As Long
Dim hPrimaryToken As Long
Dim hThread As Long
Dim lngResult As Long
Dim blnResult As Boolean
Dim start_info As STARTUPINFO
Dim proc_info As PROCESS_INFORMATION
Dim proc_attr As SECURITY_ATTRIBUTES
hThread = GetCurrentThread()
If (OpenThreadToken(hThread, TOKEN_ALL_ACCESS, True, hToken)) Then
If (DuplicateTokenEx(hToken, GENERIC_ALL, 0&,
SecurityImpersonation, _
TokenPrimary, hPrimaryToken)) Then
The issue is, we're getting an ERROR_NOACCESS (error 998 - Invalid access to
memory location) on the DuplicateTokenEx call.
However, the same calls from a test dll on the same machine, using the same
user, worked without an error.
If anybody can help me with this headache, I'll be very appreciative.
Thanks,
Paul
Ken Halter - 13 Jun 2007 20:40 GMT
> Hello All,
fwiw, the params you're sending to DuplicateTokenEx don't seem to match the
declarations I've seen.
This is from MSDN....
'=========
BOOL WINAPI DuplicateTokenEx(
HANDLE hExistingToken,
DWORD dwDesiredAccess,
LPSECURITY_ATTRIBUTES lpTokenAttributes,
SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
TOKEN_TYPE TokenType,
PHANDLE phNewToken
);
'=========
DuplicateTokenEx(hToken, GENERIC_ALL, 0&
In the line above, your 3rd param is a hard coded 0, instead of a
LPSECURITY_ATTRIBUTES type, which should be a pointer to the type
declaration below (byref pointer to your variable that's declared as that
type)
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
I don't play with security, so I'm just looking for "the obvious"

Signature
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
In Loving Memory - http://www.vbsight.com/Remembrance.htm
Mark Yudkin - 17 Jun 2007 09:40 GMT
1) Post your declarations of all APIs, as well as all variables, constants
or whatever passed to these APIs. Most errors are in these.
2) The VB6 True (-1) is not the same as the API TRUE (+1), so your call to
OpenThreadToken is wrong.
3) As Ken has pointed out, the third parameter to DuplicateTokenEx is not a
byval long.
> Hello All,
>
[quoted text clipped - 26 lines]
> Thanks,
> Paul