Gettokeninformation Failed With Error 87
Contents |
Specific Boards Windows Programming GetTokenInformation() confusion Getting started with C
Loadlibrary Failed With Error 87. The Parameter Is Incorrect
or C++ | C Tutorial | C++ Tutorial | C error 87 the parameter is incorrect windows 8 and C++ FAQ | Get a compiler | Fixes for common problems Thread: GetTokenInformation() confusion Thread error 87 the parameter is incorrect windows 7 Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 10-27-2009 #1 Necrofear
Amd Drivers
View Profile View Forum Posts Registered User Join Date Jan 2005 Posts 183 GetTokenInformation() confusion Heya all. I have spent the whole day trying to write a function that will return 0 if the process is running elevated. (It's been a while since I wrote anything Windows related.) Eventually, I wrote something close to working code: Code: int TokenIsElevated() // Returns 0 if process is elevated, 1 if process is not elevated or -1 if a function fails. { DWORD CurrentProcPID = GetCurrentProcessId(); if (!CurrentProcPID) { MessageBox(NULL, "GetCurrentProcessID function call failed.", "Test 4.exe", MB_ICONEXCLAMATION | MB_OK); return -1; } HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, CurrentProcPID); if (!hProcess) { MessageBox(NULL, "OpenProcess function call failed.", "Test 4.exe", MB_ICONEXCLAMATION | MB_OK); CloseHandle(hProcess); return -1; } PHANDLE hToken; if(OpenProcessToken(hProcess, TOKEN_READ, hToken) == 0) { MessageBox(NULL, "OpenProcessToken function call failed.", "Test 4.exe", MB_ICONEXCLAMATION | MB_OK); CloseHandle(hProcess); CloseHandle(hToken); return -1; } TOKEN_ELEVATION_TYPE ElevationType = TokenElevationTypeDefault; DWORD SizeReturned = 0; if (!GetTokenInformation(hToken, TokenElevationType, &ElevationType, sizeof(ElevationType), &SizeReturned)) { MessageBox(NULL, "GetTokenInformation function call failed.", "Test 4.exe", MB_ICONEXCLAMATION | MB_OK); CloseHandle(hProcess); CloseHandle(hToken); return -1; } if (ElevationType == TokenElevationTypeFull); { CloseHandle(hProcess); CloseHandle(hToken); return 0; } else { CloseHandle(hProcess); CloseHandle(hToken); return 1; } } The code compiled fine until I wrote this section: Code: TO
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Why does Openprocess fail with error 87 on XP and is working fine http://cboard.cprogramming.com/windows-programming/121040-gettokeninformation-confusion.html on Windows 7? up vote 0 down vote favorite 1 In my app i created a jobobject, and started a new process. After this i'm listening on an IOPort, if any new processes have been created from this process. If yes, i would like to open a handle to them and use them. Unfortunately my code works fine under Windows 7, but under XP ( 32 and 64 bit ) http://stackoverflow.com/questions/13745875/why-does-openprocess-fail-with-error-87-on-xp-and-is-working-fine-on-windows-7 OpenProcess succeeds only for the first time, but later it will fail with error 87, and i can't figure it out why. The processes exists at this time. If a new process has been created Overlapped contains its processid. Here is the code: while ( GetQueuedCompletionStatus( IOPort, &CompletionCode, &CompletionKey, &Overlapped, INFINITE ) && CompletionCode != JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO ) { if ( CompletionCode == JOB_OBJECT_MSG_NEW_PROCESS ) { //HANDLE ize; ProcessCount++; memset( ProcName, 0, sizeof( ProcName ) ); NewProcessHandle = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, ( DWORD )Overlapped ); if ( NewProcessHandle == NULL ) { printf( "\ninvalid\n\n" ); // The application closed too soon, so we couldn't get a handle to it printf( "\nPID = %d, GL:%d",Overlapped, GetLastError() ); } else { printf( "\nvalid\n\n" ); HandleArray = ( struct HandleStruct **)realloc( HandleArray, ( HandleCount + 1 ) * sizeof( struct HandleStruct *) ); HandleArray[ HandleCount ] = ( struct HandleStruct *)malloc( sizeof( struct HandleStruct ) ); HandleArray[ HandleCount ]->PID = ( DWORD* )Overlapped; HandleArray[ HandleCount ]->handle = NewProcessHandle; GetProcessNameByPID( ( DWORD )Overlapped, ProcName ); HandleArray[ HandleCount ]->Process = _strdup( ProcName ); HandleCount++; } } if ( ( CompletionCode == JOB_OBJECT_MSG_EXIT_PROCESS ) || ( CompletionCode == JOB_OBJECT_MSG_ABNORMAL_EXIT_PROCESS ) ) { ProcessCount--; for ( int i = 0; i < Handle
of Process Mandatory Level Checking and Self-elevation under UAC ★★★★★★★★★★★★★★★ msdntwtMarch 30, 20101 0 0 0 Introduction User Account Control (UAC) is a new security component in https://blogs.msdn.microsoft.com/msdnforum/2010/03/30/a-quick-start-guide-of-process-mandatory-level-checking-and-self-elevation-under-uac/ Windows Vista and newer operating systems. With UAC fully enabled, interactive administrators normally run with least user privileges. This article and the attached code samples demonstrate these frequently asked coding scenarios related to UAC. 1. How to check if the current process is running as administrator? 2. How to know if the primary access token of the current process belongs to user account error 87 that is a member of the local Administrators group, even if it currently is not elevated? 3. How to check if the current process is elevated? The elevation information is available to only Windows Vista and newer operating systems because there was no UAC and “elevation” before Windows Vista. 4. How to get the integrity level of the current process (System/High/Medium/Low/Unknown)? The integrity level the parameter is information is available to only Windows Vista and newer operating systems because there was no UAC and “integrity level” before Windows Vista. 5. How to show an UAC shield icon on the UI for tasks that requires elevation? 6. How to self-elevate the current process? 7. How to automatically elevate the process when it's started up? We provide code samples to demonstrate the above how-to scenarios in three programming languages (native VC++, VC#, VB.NET) to meet the needs of different developers. Language Sample VC++ CppUACSelfElevation VC# CSUACSelfElevation VB.NET VBUACSelfElevation The code samples are part of Microsoft All-In-One Code Framework, which is a centralized code sample solution from Microsoft. You can download the code from the project’s Download page: http://1code.codeplex.com/releases/. Background Microsoft All-In-One Code Framework delineates the framework and skeleton of most Microsoft development techniques (e.g., COM, Data Access, IPC) using typical sample codes in different programming languages (e.g., Visual C#, VB.NET, Visual C++). Each sample is elaborately selected, composed, and documented to demonstrate one frequently-asked, tested or used coding scenario based on Microsoft’s support experience in MSDN newsgroups and forums. Demo This is a quick demo of the attache