Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-03-2007, 12:41 PM
Jophry Jophry is offline
Newbie
 
Join Date: Jan 2007
Posts: 1
Rep Power: 0
Jophry is on a distinguished road
Default What is wrong with this code convertion ?

Hi
I have this code in c++, and I want to gain full access over an application.
Code:
HANDLE hToken; 
TOKEN_PRIVILEGES tkp; 
 
// Get a token for this process. 
if(!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
	return FALSE;
 
// Get the LUID for the shutdown privilege. 
LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid); 
tkp.PrivilegeCount = 1;  // one privilege to set    
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 
 
// Get the shutdown privilege for this process. 
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
and it works, but here comes my problem.
I want to convert this code to Pascal. All functions return true, but a call of GetLastError() just after AdjustTokenPrivileges() gives me an errorcode 1300 ( Not all privileges or groups referenced are assigned to the caller ). So what do I do wrong ?
Here's my code ( in Pascal )
Code:
 var
  hToken : handle;
  tp: TOKEN_PRIVILEGES;

   OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, @hToken);
   LookupPrivilegeValue( NULL, SE_DEBUG_NAME, @tp.Privileges[0].LUID );
   tp.PrivilegeCount := 1;
   tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
   AdjustTokenPrivileges( hToken, FALSE, @tp, sizeof(TOKEN_PRIVILEGES), 0, 0 );
   GetLastError(); // <- Returns 1300 :/
So please help me. What is wrong here I've compiled this code by using Dev-Pas v1.9.2.

Last edited by Jophry; 01-03-2007 at 02:47 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 01-04-2007, 01:10 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,418
Last Blog:
wxWidgets is NOT code ...
Rep Power: 37
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default

Not seeing how AdjustTokenPrivileges or GetLastError are implemented, it's kind of tough to say.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Code: Capture Code from USB Camera MrNobody VB Tutorials 53 12-01-2008 10:16 PM
Basic Calculator AfTriX VB Tutorials 3 02-29-2008 09:53 AM
Please Help With A C Program!! siren C and C++ 7 04-17-2007 09:45 AM
Where to Put PHP Code clookid PHP Tutorials 1 01-11-2007 09:44 PM


All times are GMT -5. The time now is 03:09 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads