Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Win API / June 2007



Tip: Looking for answers? Try searching our database.

DuplicateTokenEX - getting ERROR_NOACCESS (998)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paulie GoNuts - 13 Jun 2007 19:23 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.