none
checktokenmembership RRS feed

  • Question

  • I need to determine if a user has administrative rights in VC++ 6.0.  I found several articles that address this.  One of the keys is the function CheckTokenMembership.  The VC++ 6.0 help says to include winbase.h to use this function.  Howver, when I include winbase.h, CheckTokenMembership is not recognized.  I checked that file, and all files in my VC98\Include folder, and CheckTokenMembership is not defined in any of those files.  Nor is it in any file in the MFC\Include or MFC\SRC folders.  Does anyone know if this function is defined in VC++ 6.0, and if so, where?  If it's not defined for VC++ 6.0, does anyone know how to determine if a user has admin rights?  Thanks in advance.
    genush
    Wednesday, May 4, 2011 5:18 PM

Answers

  • The OS at the time of VC6 on the NT side of things was Windows NT4. Windows 2000 was still in development but since they would have used the most up to date release version of Windows, it would have been NT4.

    For the function pointer, it should be declared as

    typedef BOOL (WINAPI *CheckTokenMembershipPtr)(
     HANDLE TokenHandle,
     PSID SidToCheck,
     PBOOL IsMember
    );
    

    Well, you can shorten the type name if you want, since it doesn't need to be that long.

     


    This is a signature

    Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.
    Visit my (not very good) blog at
    http://ccprogramming.wordpress.com/
    Wednesday, May 4, 2011 9:24 PM

All replies

  • Try including windows.h.
    «_Superman_»
    Microsoft MVP (Visual C++)

    Polymorphism in C
    Wednesday, May 4, 2011 5:24 PM
  • Yes, I had tried that too, but same thing, CheckTokenMembership is an undeclared identifier when I try to compile.
    genush
    Wednesday, May 4, 2011 5:28 PM
  • +1 to Superman.  See http://msdn.microsoft.com/en-us/library/aa376389(VS.85).aspx.  Near the end it tells you the header file to include.  Same for every other Windows API.  MSDN Online is great!

    But FYI, newer operating systems have a shortcut function.  I think it is a shell function (SHXXXX), but I just can't find it.


    MCP
    Wednesday, May 4, 2011 5:30 PM
  • It says to include windows.h, which is what Superman suggested, but as I mentioned to him, that didn't help.  I checked the windows.h (and winbase.h) files, and neither one defines function CheckTokenMembership.  And as I mentioned in my original post, I checked all the VC++ 6.0 folders and that function is not defined in any header file.
    genush
    Wednesday, May 4, 2011 6:01 PM
  • If you cannot find CheckTokenMembership in header files, then it seems to be unavailable in Visual C++ 6. But if this function is available in Operating System, and there is no simpler approach to solve your problem, you can consider an alternative way. First load the library using LoadLibrary(“Advapi32.dll”). Then extract the function pointer using GetProcAddress. If this succeeds, cast the value to a function pointer that corresponds to the function declaration shown in documentation. Then you can invoke the function.

    Wednesday, May 4, 2011 7:11 PM
  • +1 to Viorel.  But then maybe we can try to respond the following questions:  What operating system are you targetting?  The function exists since Windows 2000.  Also, what is the SDK in Visual C++ 6.0?  If it predates Windows 2000, all you need to do is install the Windows 7 SDK and just #define _WIN32_WINNT to the version of your target OS:  0x0500 for Windows 2000, or 0x0501 for Windows XP.
    MCP
    Wednesday, May 4, 2011 7:21 PM
  • Hmm, I did as you suggested but I'm getting an error when I call the function = "The value of ESP was not properly saved across a function call.  This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention."  I must be missing something obvious because it sure looks like I have the function declared correctly.  I'll keep looking, and thanks for your help.
    genush
    Wednesday, May 4, 2011 9:04 PM
  • The OS is XP.  I'm not sure what the SDK is with this release of VC++ 6.0. I'm using SP 6 if that makes any difference.
    genush
    Wednesday, May 4, 2011 9:08 PM
  • VC6 was released back in the Win98 timeframe, so likely the SDK installed with it targerts Win98 and NT4.

    The current SDK does not VC6, and has not for a while. (see here).  If you download the last SDK that supports VC6 you can develop for XP but not really anything newer.  You can, of course, always call LoadLibrary and GetProcAddress to manually call any newer functions.

    Wednesday, May 4, 2011 9:14 PM
  • The OS at the time of VC6 on the NT side of things was Windows NT4. Windows 2000 was still in development but since they would have used the most up to date release version of Windows, it would have been NT4.

    For the function pointer, it should be declared as

    typedef BOOL (WINAPI *CheckTokenMembershipPtr)(
     HANDLE TokenHandle,
     PSID SidToCheck,
     PBOOL IsMember
    );
    

    Well, you can shorten the type name if you want, since it doesn't need to be that long.

     


    This is a signature

    Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.
    Visit my (not very good) blog at
    http://ccprogramming.wordpress.com/
    Wednesday, May 4, 2011 9:24 PM
  • Ahh, I didn't have the WINAPI in my declaration.  Adding that fixed the problem, and it works fine now.  Thanks to all for the help and education.  :)
    genush
    Wednesday, May 4, 2011 10:00 PM